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
+95 -48
View File
@@ -84,19 +84,19 @@ class Tests_URL extends WP_UnitTestCase {
return array(
array(
null,
'/wp-admin/'
'/wp-admin/',
),
array(
0,
'/wp-admin/'
'/wp-admin/',
),
array(
-1,
'/wp-admin/'
'/wp-admin/',
),
array(
'///',
'/wp-admin/'
'/wp-admin/',
),
array(
'',
@@ -152,47 +152,47 @@ class Tests_URL extends WP_UnitTestCase {
return array(
array(
null,
"",
'',
),
array(
0,
"",
'',
),
array(
-1,
"",
'',
),
array(
'///',
"/",
'/',
),
array(
'',
"",
'',
),
array(
'foo',
"/foo",
'/foo',
),
array(
'/foo',
"/foo",
'/foo',
),
array(
'/foo/',
"/foo/",
'/foo/',
),
array(
'foo.php',
"/foo.php",
'/foo.php',
),
array(
'/foo.php',
"/foo.php",
'/foo.php',
),
array(
'/foo.php?bar=1',
"/foo.php?bar=1",
'/foo.php?bar=1',
),
);
}
@@ -202,7 +202,7 @@ class Tests_URL extends WP_UnitTestCase {
// Pretend to be in the site admin
set_current_screen( 'dashboard' );
$home = get_option('home');
$home = get_option( 'home' );
// home_url() should return http when in the admin
$_SERVER['HTTPS'] = 'on';
@@ -215,16 +215,15 @@ class Tests_URL extends WP_UnitTestCase {
set_current_screen( 'front' );
$this->assertEquals( $home, home_url() );
$_SERVER['HTTPS'] = 'on';
$home = str_replace('http://', 'https://', $home);
$home = str_replace( 'http://', 'https://', $home );
$this->assertEquals( $home, home_url() );
// Test with https in home
update_option( 'home', set_url_scheme( $home, 'https' ) );
// Pretend to be in the site admin
set_current_screen( 'dashboard' );
$home = get_option('home');
$home = get_option( 'home' );
// home_url() should return whatever scheme is set in the home option when in the admin
$_SERVER['HTTPS'] = 'on';
@@ -254,7 +253,7 @@ class Tests_URL extends WP_UnitTestCase {
$home = network_home_url();
// home_url() should return http when in the admin
$this->assertEquals( 0, strpos( $home, 'http://') );
$this->assertEquals( 0, strpos( $home, 'http://' ) );
$_SERVER['HTTPS'] = 'on';
$this->assertEquals( $home, network_home_url() );
@@ -265,15 +264,16 @@ class Tests_URL extends WP_UnitTestCase {
set_current_screen( 'front' );
$this->assertEquals( $home, network_home_url() );
$_SERVER['HTTPS'] = 'on';
$home = str_replace('http://', 'https://', $home);
$home = str_replace( 'http://', 'https://', $home );
$this->assertEquals( $home, network_home_url() );
$GLOBALS['current_screen'] = $screen;
}
function test_set_url_scheme() {
if ( ! function_exists( 'set_url_scheme' ) )
if ( ! function_exists( 'set_url_scheme' ) ) {
return;
}
$links = array(
'http://wordpress.org/',
@@ -300,11 +300,11 @@ class Tests_URL extends WP_UnitTestCase {
'/',
'/',
'/news/',
''
'',
);
$forced_admin = force_ssl_admin();
$i = 0;
$i = 0;
foreach ( $links as $link ) {
$this->assertEquals( $https_links[ $i ], set_url_scheme( $link, 'https' ) );
$this->assertEquals( $http_links[ $i ], set_url_scheme( $link, 'http' ) );
@@ -335,13 +335,14 @@ class Tests_URL extends WP_UnitTestCase {
}
public function test_get_adjacent_post() {
$now = time();
$post_id = self::factory()->post->create( array( 'post_date' => date( 'Y-m-d H:i:s', $now - 1 ) ) );
$now = time();
$post_id = self::factory()->post->create( array( 'post_date' => date( 'Y-m-d H:i:s', $now - 1 ) ) );
$post_id2 = self::factory()->post->create( array( 'post_date' => date( 'Y-m-d H:i:s', $now ) ) );
if ( ! isset( $GLOBALS['post'] ) )
if ( ! isset( $GLOBALS['post'] ) ) {
$GLOBALS['post'] = null;
$orig_post = $GLOBALS['post'];
}
$orig_post = $GLOBALS['post'];
$GLOBALS['post'] = get_post( $post_id2 );
$p = get_adjacent_post();
@@ -369,13 +370,24 @@ class Tests_URL extends WP_UnitTestCase {
* @ticket 30287
*/
public function test_get_adjacent_post_should_return_private_posts_belonging_to_the_current_user() {
$u = self::factory()->user->create( array( 'role' => 'author' ) );
$u = self::factory()->user->create( array( 'role' => 'author' ) );
$old_uid = get_current_user_id();
wp_set_current_user( $u );
$now = time();
$p1 = self::factory()->post->create( array( 'post_author' => $u, 'post_status' => 'private', 'post_date' => date( 'Y-m-d H:i:s', $now - 1 ) ) );
$p2 = self::factory()->post->create( array( 'post_author' => $u, 'post_date' => date( 'Y-m-d H:i:s', $now ) ) );
$p1 = self::factory()->post->create(
array(
'post_author' => $u,
'post_status' => 'private',
'post_date' => date( 'Y-m-d H:i:s', $now - 1 ),
)
);
$p2 = self::factory()->post->create(
array(
'post_author' => $u,
'post_date' => date( 'Y-m-d H:i:s', $now ),
)
);
if ( ! isset( $GLOBALS['post'] ) ) {
$GLOBALS['post'] = null;
@@ -395,14 +407,25 @@ class Tests_URL extends WP_UnitTestCase {
* @ticket 30287
*/
public function test_get_adjacent_post_should_return_private_posts_belonging_to_other_users_if_the_current_user_can_read_private_posts() {
$u1 = self::factory()->user->create( array( 'role' => 'author' ) );
$u2 = self::factory()->user->create( array( 'role' => 'administrator' ) );
$u1 = self::factory()->user->create( array( 'role' => 'author' ) );
$u2 = self::factory()->user->create( array( 'role' => 'administrator' ) );
$old_uid = get_current_user_id();
wp_set_current_user( $u2 );
$now = time();
$p1 = self::factory()->post->create( array( 'post_author' => $u1, 'post_status' => 'private', 'post_date' => date( 'Y-m-d H:i:s', $now - 1 ) ) );
$p2 = self::factory()->post->create( array( 'post_author' => $u1, 'post_date' => date( 'Y-m-d H:i:s', $now ) ) );
$p1 = self::factory()->post->create(
array(
'post_author' => $u1,
'post_status' => 'private',
'post_date' => date( 'Y-m-d H:i:s', $now - 1 ),
)
);
$p2 = self::factory()->post->create(
array(
'post_author' => $u1,
'post_date' => date( 'Y-m-d H:i:s', $now ),
)
);
if ( ! isset( $GLOBALS['post'] ) ) {
$GLOBALS['post'] = null;
@@ -422,15 +445,31 @@ class Tests_URL extends WP_UnitTestCase {
* @ticket 30287
*/
public function test_get_adjacent_post_should_not_return_private_posts_belonging_to_other_users_if_the_current_user_cannot_read_private_posts() {
$u1 = self::factory()->user->create( array( 'role' => 'author' ) );
$u2 = self::factory()->user->create( array( 'role' => 'author' ) );
$u1 = self::factory()->user->create( array( 'role' => 'author' ) );
$u2 = self::factory()->user->create( array( 'role' => 'author' ) );
$old_uid = get_current_user_id();
wp_set_current_user( $u2 );
$now = time();
$p1 = self::factory()->post->create( array( 'post_author' => $u1, 'post_date' => date( 'Y-m-d H:i:s', $now - 2 ) ) );
$p2 = self::factory()->post->create( array( 'post_author' => $u1, 'post_status' => 'private', 'post_date' => date( 'Y-m-d H:i:s', $now - 1 ) ) );
$p3 = self::factory()->post->create( array( 'post_author' => $u1, 'post_date' => date( 'Y-m-d H:i:s', $now ) ) );
$p1 = self::factory()->post->create(
array(
'post_author' => $u1,
'post_date' => date( 'Y-m-d H:i:s', $now - 2 ),
)
);
$p2 = self::factory()->post->create(
array(
'post_author' => $u1,
'post_status' => 'private',
'post_date' => date( 'Y-m-d H:i:s', $now - 1 ),
)
);
$p3 = self::factory()->post->create(
array(
'post_author' => $u1,
'post_date' => date( 'Y-m-d H:i:s', $now ),
)
);
if ( ! isset( $GLOBALS['post'] ) ) {
$GLOBALS['post'] = null;
@@ -466,18 +505,26 @@ class Tests_URL extends WP_UnitTestCase {
);
foreach ( $functions as $function ) {
$this->assertEquals( call_user_func( $function, '/' ) . '../',
call_user_func( $function, '../' ) );
$this->assertEquals( call_user_func( $function, '/' ) . 'something...here',
call_user_func( $function, 'something...here' ) );
$this->assertEquals(
call_user_func( $function, '/' ) . '../',
call_user_func( $function, '../' )
);
$this->assertEquals(
call_user_func( $function, '/' ) . 'something...here',
call_user_func( $function, 'something...here' )
);
}
// These functions accept a blog ID argument.
foreach ( array( 'get_site_url', 'get_home_url', 'get_admin_url' ) as $function ) {
$this->assertEquals( call_user_func( $function, null, '/' ) . '../',
call_user_func( $function, null, '../' ) );
$this->assertEquals( call_user_func( $function, null, '/' ) . 'something...here',
call_user_func( $function, null, 'something...here' ) );
$this->assertEquals(
call_user_func( $function, null, '/' ) . '../',
call_user_func( $function, null, '../' )
);
$this->assertEquals(
call_user_func( $function, null, '/' ) . 'something...here',
call_user_func( $function, null, 'something...here' )
);
}
}
}