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
+76 -60
View File
@@ -1,5 +1,5 @@
<?php
require_once( ABSPATH . 'wp-admin/custom-header.php');
require_once( ABSPATH . 'wp-admin/custom-header.php' );
/**
* @group image
@@ -16,16 +16,18 @@ class Tests_Image_Header extends WP_UnitTestCase {
function test_header_image_has_correct_dimensions_with_max_width() {
global $_wp_theme_features;
$_wp_theme_features['custom-header'][0]['max-width'] = 1600;
$_wp_theme_features['custom-header'][0]['width'] = 1200;
$_wp_theme_features['custom-header'][0]['height'] = 230;
$_wp_theme_features['custom-header'][0]['flex-width'] = false;
$_wp_theme_features['custom-header'][0]['max-width'] = 1600;
$_wp_theme_features['custom-header'][0]['width'] = 1200;
$_wp_theme_features['custom-header'][0]['height'] = 230;
$_wp_theme_features['custom-header'][0]['flex-width'] = false;
$_wp_theme_features['custom-header'][0]['flex-height'] = false;
$dimensions = $this->custom_image_header->get_header_dimensions( array(
'width' => 1600,
'height' => 1200,
) );
$dimensions = $this->custom_image_header->get_header_dimensions(
array(
'width' => 1600,
'height' => 1200,
)
);
$this->assertEquals( 1200, $dimensions['dst_width'] );
$this->assertEquals( 230, $dimensions['dst_height'] );
@@ -35,15 +37,17 @@ class Tests_Image_Header extends WP_UnitTestCase {
global $_wp_theme_features;
unset( $_wp_theme_features['custom-header'][0]['max-width'] );
$_wp_theme_features['custom-header'][0]['width'] = 1200;
$_wp_theme_features['custom-header'][0]['height'] = 230;
$_wp_theme_features['custom-header'][0]['flex-width'] = false;
$_wp_theme_features['custom-header'][0]['width'] = 1200;
$_wp_theme_features['custom-header'][0]['height'] = 230;
$_wp_theme_features['custom-header'][0]['flex-width'] = false;
$_wp_theme_features['custom-header'][0]['flex-height'] = false;
$dimensions = $this->custom_image_header->get_header_dimensions( array(
'width' => 1600,
'height' => 1200,
) );
$dimensions = $this->custom_image_header->get_header_dimensions(
array(
'width' => 1600,
'height' => 1200,
)
);
$this->assertEquals( 1200, $dimensions['dst_width'] );
$this->assertEquals( 230, $dimensions['dst_height'] );
@@ -53,15 +57,17 @@ class Tests_Image_Header extends WP_UnitTestCase {
global $_wp_theme_features;
unset( $_wp_theme_features['custom-header'][0]['max-width'] );
$_wp_theme_features['custom-header'][0]['width'] = 1200;
$_wp_theme_features['custom-header'][0]['height'] = 230;
$_wp_theme_features['custom-header'][0]['flex-width'] = false;
$_wp_theme_features['custom-header'][0]['width'] = 1200;
$_wp_theme_features['custom-header'][0]['height'] = 230;
$_wp_theme_features['custom-header'][0]['flex-width'] = false;
$_wp_theme_features['custom-header'][0]['flex-height'] = true;
$dimensions = $this->custom_image_header->get_header_dimensions( array(
'width' => 1600,
'height' => 1200,
) );
$dimensions = $this->custom_image_header->get_header_dimensions(
array(
'width' => 1600,
'height' => 1200,
)
);
$this->assertEquals( 1200, $dimensions['dst_width'] );
$this->assertEquals( 900, $dimensions['dst_height'] );
@@ -71,15 +77,17 @@ class Tests_Image_Header extends WP_UnitTestCase {
global $_wp_theme_features;
unset( $_wp_theme_features['custom-header'][0]['max-width'] );
$_wp_theme_features['custom-header'][0]['width'] = 1200;
$_wp_theme_features['custom-header'][0]['height'] = 230;
$_wp_theme_features['custom-header'][0]['flex-width'] = true;
$_wp_theme_features['custom-header'][0]['width'] = 1200;
$_wp_theme_features['custom-header'][0]['height'] = 230;
$_wp_theme_features['custom-header'][0]['flex-width'] = true;
$_wp_theme_features['custom-header'][0]['flex-height'] = false;
$dimensions = $this->custom_image_header->get_header_dimensions( array(
'width' => 1600,
'height' => 1200,
) );
$dimensions = $this->custom_image_header->get_header_dimensions(
array(
'width' => 1600,
'height' => 1200,
)
);
$this->assertEquals( 1500, $dimensions['dst_width'] ); // max width
$this->assertEquals( 230, $dimensions['dst_height'] );
@@ -88,28 +96,32 @@ class Tests_Image_Header extends WP_UnitTestCase {
function test_header_image_has_correct_dimensions_with_flex_width_and_height() {
global $_wp_theme_features;
$_wp_theme_features['custom-header'][0]['max-width'] = 1800;
$_wp_theme_features['custom-header'][0]['width'] = 1200;
$_wp_theme_features['custom-header'][0]['height'] = 230;
$_wp_theme_features['custom-header'][0]['flex-width'] = true;
$_wp_theme_features['custom-header'][0]['max-width'] = 1800;
$_wp_theme_features['custom-header'][0]['width'] = 1200;
$_wp_theme_features['custom-header'][0]['height'] = 230;
$_wp_theme_features['custom-header'][0]['flex-width'] = true;
$_wp_theme_features['custom-header'][0]['flex-height'] = true;
$dimensions = $this->custom_image_header->get_header_dimensions( array(
'width' => 1600,
'height' => 1200,
) );
$dimensions = $this->custom_image_header->get_header_dimensions(
array(
'width' => 1600,
'height' => 1200,
)
);
$this->assertEquals( 1600, $dimensions['dst_width'] );
$this->assertEquals( 1200, $dimensions['dst_height'] );
}
function test_create_attachment_object() {
$id = wp_insert_attachment( array(
'post_status' => 'publish',
'post_title' => 'foo.png',
'post_type' => 'post',
'guid' => 'http://localhost/foo.png'
) );
$id = wp_insert_attachment(
array(
'post_status' => 'publish',
'post_title' => 'foo.png',
'post_type' => 'post',
'guid' => 'http://localhost/foo.png',
)
);
$cropped = 'foo-cropped.png';
@@ -121,15 +133,17 @@ class Tests_Image_Header extends WP_UnitTestCase {
}
function test_insert_cropped_attachment() {
$id = wp_insert_attachment( array(
'post_status' => 'publish',
'post_title' => 'foo.png',
'post_type' => 'post',
'guid' => 'http://localhost/foo.png'
) );
$id = wp_insert_attachment(
array(
'post_status' => 'publish',
'post_title' => 'foo.png',
'post_type' => 'post',
'guid' => 'http://localhost/foo.png',
)
);
$cropped = 'foo-cropped.png';
$object = $this->custom_image_header->create_attachment_object( $cropped, $id );
$object = $this->custom_image_header->create_attachment_object( $cropped, $id );
$cropped_id = $this->custom_image_header->insert_attachment( $object, $cropped );
@@ -141,16 +155,18 @@ class Tests_Image_Header extends WP_UnitTestCase {
* @ticket 21819
*/
function test_check_get_previous_crop() {
$id = wp_insert_attachment( array(
'post_status' => 'publish',
'post_title' => 'foo.png',
'post_type' => 'post',
'guid' => 'http://localhost/foo.png'
) );
$id = wp_insert_attachment(
array(
'post_status' => 'publish',
'post_title' => 'foo.png',
'post_type' => 'post',
'guid' => 'http://localhost/foo.png',
)
);
// Create inital crop object.
$cropped_1 = 'foo-cropped-1.png';
$object = $this->custom_image_header->create_attachment_object( $cropped_1, $id );
$object = $this->custom_image_header->create_attachment_object( $cropped_1, $id );
// Ensure no previous crop exists.
$previous = $this->custom_image_header->get_previous_crop( $object );
@@ -158,13 +174,13 @@ class Tests_Image_Header extends WP_UnitTestCase {
// Create the inital crop attachment and set it as the header.
$cropped_1_id = $this->custom_image_header->insert_attachment( $object, $cropped_1 );
$key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();
$key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();
update_post_meta( $cropped_1_id, $key, time() );
update_post_meta( $cropped_1_id, '_wp_attachment_is_custom_header', get_stylesheet() );
// Create second crop.
$cropped_2 = 'foo-cropped-2.png';
$object = $this->custom_image_header->create_attachment_object( $cropped_2, $id );
$object = $this->custom_image_header->create_attachment_object( $cropped_2, $id );
// Test that a previous crop is found.
$previous = $this->custom_image_header->get_previous_crop( $object );