diff options
author | Dominik Schilling (ocean90) <ocean90@git.wordpress.org> | 2016-04-21 21:20:26 +0000 |
---|---|---|
committer | Dominik Schilling (ocean90) <ocean90@git.wordpress.org> | 2016-04-21 21:20:26 +0000 |
commit | 153610292d34207316f10b4e19e44a5d59efa25a (patch) | |
tree | 13f0cf874e0f6dcdd72d6e63b4fb568d0c7b0ab3 | |
parent | d434c58404fa8ac6ede280d78bdba0072b8608d1 (diff) | |
download | wordpress-153610292d34207316f10b4e19e44a5d59efa25a.tar.gz wordpress-153610292d34207316f10b4e19e44a5d59efa25a.zip |
Media: Remove an extra quote when sending a link of a media file to the editor.
Introduced in [37035].
Props joemcgill, swissspidy, boonebgorges.
Fixes #36578.
git-svn-id: https://develop.svn.wordpress.org/trunk@37288 602fd350-edb4-49c9-b593-d223f7449a82
-rw-r--r-- | src/wp-admin/includes/ajax-actions.php | 2 | ||||
-rw-r--r-- | tests/phpunit/includes/testcase-ajax.php | 2 | ||||
-rw-r--r-- | tests/phpunit/tests/ajax/Attachments.php | 112 |
3 files changed, 114 insertions, 2 deletions
diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index f3d8e839f8..e3b345c53c 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -2602,7 +2602,7 @@ function wp_ajax_send_attachment_to_editor() { $rel = $rel ? ' rel="attachment wp-att-' . $id . '"' : ''; // Hard-coded string, $id is already sanitized if ( ! empty( $url ) ) { - $html = '<a href="' . esc_url( $url ) . '"' . $rel . '">' . $html . '</a>'; + $html = '<a href="' . esc_url( $url ) . '"' . $rel . '>' . $html . '</a>'; } } diff --git a/tests/phpunit/includes/testcase-ajax.php b/tests/phpunit/includes/testcase-ajax.php index ea809d560e..c4466aa3a2 100644 --- a/tests/phpunit/includes/testcase-ajax.php +++ b/tests/phpunit/includes/testcase-ajax.php @@ -50,7 +50,7 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase { 'menu-locations-save', 'menu-quick-search', 'meta-box-order', 'get-permalink', 'sample-permalink', 'inline-save', 'inline-save-tax', 'find_posts', 'widgets-order', 'save-widget', 'set-post-thumbnail', 'date_format', 'time_format', 'wp-fullscreen-save-post', - 'wp-remove-post-lock', 'dismiss-wp-pointer', 'heartbeat', 'nopriv_heartbeat', 'get-revision-diffs', + 'wp-remove-post-lock', 'dismiss-wp-pointer', 'send-attachment-to-editor', 'heartbeat', 'nopriv_heartbeat', 'get-revision-diffs', 'save-user-color-scheme', 'update-widget', 'query-themes', 'parse-embed', 'set-attachment-thumbnail', 'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin', 'press-this-save-post', 'press-this-add-category', 'crop-image', 'generate-password', diff --git a/tests/phpunit/tests/ajax/Attachments.php b/tests/phpunit/tests/ajax/Attachments.php new file mode 100644 index 0000000000..3ba9ba7c3a --- /dev/null +++ b/tests/phpunit/tests/ajax/Attachments.php @@ -0,0 +1,112 @@ +<?php +/** + * Admin ajax functions to be tested + */ +require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' ); + +/** + * Testing ajax attachment handling. + * + * @group ajax + */ +class Tests_Ajax_Attachments extends WP_Ajax_UnitTestCase { + /** + * @ticket 36578 + */ + public function test_wp_ajax_send_attachment_to_editor_should_return_an_image() { + // Become an administrator + $post = $_POST; + $user_id = self::factory()->user->create( array( + 'role' => 'administrator', + 'user_login' => 'user_36578_administrator', + 'user_email' => 'user_36578_administrator@example.com', + ) ); + wp_set_current_user( $user_id ); + $_POST = array_merge($_POST, $post); + + $filename = DIR_TESTDATA . '/images/canola.jpg'; + $contents = file_get_contents( $filename ); + + $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $attachment = $this->_make_attachment( $upload ); + + // Set up a default request + $_POST['nonce'] = wp_create_nonce( 'media-send-to-editor' ); + $_POST['html'] = 'Bar Baz'; + $_POST['post_id'] = 0; + $_POST['attachment'] = array( + 'id' => $attachment, + 'align' => 'left', + 'image-size' => 'large', + 'image_alt' => 'Foo bar', + 'url' => 'http://example.com/', + ); + + // Make the request + try { + $this->_handleAjax( 'send-attachment-to-editor' ); + } catch ( WPAjaxDieContinueException $e ) { + unset( $e ); + } + + // Get the response. + $response = json_decode( $this->_last_response, true ); + + $expected = get_image_send_to_editor( $attachment, '', '', 'left', 'http://example.com/', false, 'large', 'Foo bar' ); + + // Ensure everything is correct + $this->assertTrue( $response['success'] ); + $this->assertEquals( $expected, $response['data'] ); + } + + /** + * @ticket 36578 + */ + public function test_wp_ajax_send_attachment_to_editor_should_return_a_link() { + // Become an administrator + $post = $_POST; + $user_id = self::factory()->user->create( array( + 'role' => 'administrator', + 'user_login' => 'user_36578_administrator', + 'user_email' => 'user_36578_administrator@example.com', + ) ); + wp_set_current_user( $user_id ); + $_POST = array_merge($_POST, $post); + + $filename = DIR_TESTDATA . '/formatting/entities.txt'; + $contents = file_get_contents( $filename ); + + $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $attachment = $this->_make_attachment( $upload ); + + // Set up a default request + $_POST['nonce'] = wp_create_nonce( 'media-send-to-editor' ); + $_POST['html'] = 'Bar Baz'; + $_POST['post_id'] = 0; + $_POST['attachment'] = array( + 'id' => $attachment, + 'post_title' => 'Foo bar', + 'url' => get_attachment_link( $attachment ), + ); + + // Make the request + try { + $this->_handleAjax( 'send-attachment-to-editor' ); + } catch ( WPAjaxDieContinueException $e ) { + unset( $e ); + } + + // Get the response. + $response = json_decode( $this->_last_response, true ); + + $expected = sprintf( + '<a href="%s" rel="attachment wp-att-%d">Foo bar</a>', + get_attachment_link( $attachment ), + $attachment + ); + + // Ensure everything is correct + $this->assertTrue( $response['success'] ); + $this->assertEquals( $expected, $response['data'] ); + } +} |