mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Grouped backports to the 5.1 branch.
- Media: Prevent CSRF setting attachment thumbnails. - Embeds: Add protocol validation for WordPress Embed code. - I18N: Introduce sanitization function for locale. - Editor: Ensure block comments are of a valid form. Merges [55760-55764] to the 5.1 branch. Props dd32, isabel_brison, martinkrcho, matveb, ocean90, paulkevan, peterwilsoncc, timothyblynjacobs, xknown, youknowriad. git-svn-id: https://develop.svn.wordpress.org/branches/5.1@55790 602fd350-edb4-49c9-b593-d223f7449a82
- Loading branch information
Showing
13 changed files
with
217 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,4 +113,95 @@ public function test_wp_ajax_send_attachment_to_editor_should_return_a_link() { | |
$this->assertTrue( $response['success'] ); | ||
$this->assertEquals( $expected, $response['data'] ); | ||
} | ||
|
||
public function test_wp_ajax_set_attachment_thumbnail_success() { | ||
// Become an administrator. | ||
$post = $_POST; | ||
$user_id = self::factory()->user->create( | ||
array( | ||
'role' => 'administrator', | ||
'user_login' => 'user_36578_administrator', | ||
'user_email' => '[email protected]', | ||
) | ||
); | ||
wp_set_current_user( $user_id ); | ||
$_POST = array_merge( $_POST, $post ); | ||
|
||
// Upload the attachment itself. | ||
$filename = DIR_TESTDATA . '/uploads/small-audio.mp3'; | ||
$contents = file_get_contents( $filename ); | ||
|
||
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); | ||
$attachment = $this->_make_attachment( $upload ); | ||
|
||
// Upload the thumbnail. | ||
$filename = DIR_TESTDATA . '/images/waffles.jpg'; | ||
$contents = file_get_contents( $filename ); | ||
|
||
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); | ||
$thumbnail = $this->_make_attachment( $upload ); | ||
|
||
// Set up a default request. | ||
$_POST['_ajax_nonce'] = wp_create_nonce( 'set-attachment-thumbnail' ); | ||
$_POST['thumbnail_id'] = $thumbnail; | ||
$_POST['urls'] = array( wp_get_attachment_url( $attachment ) ); | ||
|
||
// Make the request. | ||
try { | ||
$this->_handleAjax( 'set-attachment-thumbnail' ); | ||
} catch ( WPAjaxDieContinueException $e ) { | ||
unset( $e ); | ||
} | ||
|
||
// Get the response. | ||
$response = json_decode( $this->_last_response, true ); | ||
|
||
// Ensure everything is correct. | ||
$this->assertTrue( $response['success'] ); | ||
} | ||
|
||
public function test_wp_ajax_set_attachment_thumbnail_missing_nonce() { | ||
// Become an administrator. | ||
$post = $_POST; | ||
$user_id = self::factory()->user->create( | ||
array( | ||
'role' => 'administrator', | ||
'user_login' => 'user_36578_administrator', | ||
'user_email' => '[email protected]', | ||
) | ||
); | ||
wp_set_current_user( $user_id ); | ||
$_POST = array_merge( $_POST, $post ); | ||
|
||
// Upload the attachment itself. | ||
$filename = DIR_TESTDATA . '/uploads/small-audio.mp3'; | ||
$contents = file_get_contents( $filename ); | ||
|
||
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); | ||
$attachment = $this->_make_attachment( $upload ); | ||
|
||
// Upload the thumbnail. | ||
$filename = DIR_TESTDATA . '/images/waffles.jpg'; | ||
$contents = file_get_contents( $filename ); | ||
|
||
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); | ||
$thumbnail = $this->_make_attachment( $upload ); | ||
|
||
// Set up a default request. | ||
$_POST['thumbnail_id'] = $thumbnail; | ||
$_POST['urls'] = array( wp_get_attachment_url( $attachment ) ); | ||
|
||
// Make the request. | ||
try { | ||
$this->_handleAjax( 'set-attachment-thumbnail' ); | ||
} catch ( WPAjaxDieContinueException $e ) { | ||
unset( $e ); | ||
} | ||
|
||
// Get the response. | ||
$response = json_decode( $this->_last_response, true ); | ||
|
||
// Check that success is false without sending nonce. | ||
$this->assertFalse( $response['success'] ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/** | ||
* @group formatting | ||
* | ||
* @covers ::sanitize_locale_name | ||
*/ | ||
class Tests_Formatting_SanitizeLocaleName extends WP_UnitTestCase { | ||
/** | ||
* @dataProvider data_sanitize_locale_name_returns_non_empty_string | ||
*/ | ||
public function test_sanitize_locale_name_returns_non_empty_string( $expected, $input ) { | ||
$this->assertSame( $expected, sanitize_locale_name( $input ) ); | ||
} | ||
|
||
public function data_sanitize_locale_name_returns_non_empty_string() { | ||
return array( | ||
// array( expected, input ) | ||
array( 'en_US', 'en_US' ), | ||
array( 'en', 'en' ), | ||
array( 'fr_FR', 'fr_FR' ), | ||
array( 'fr_FR', 'fr_FR' ), | ||
array( 'fr_FR-e2791ba830489d23043be8650a22a22b', 'fr_FR-e2791ba830489d23043be8650a22a22b' ), | ||
array( '-fr_FRmo', '-fr_FR.mo' ), | ||
array( '12324', '$12324' ), | ||
array( '4124FRRa', '/4124$$$%%FRRa' ), | ||
array( 'FR', '<FR' ), | ||
array( 'FR_FR', 'FR_FR' ), | ||
array( '--__', '--__' ), | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider data_sanitize_locale_name_returns_empty_string | ||
*/ | ||
public function test_sanitize_locale_name_returns_empty_string( $input ) { | ||
$this->assertSame( '', sanitize_locale_name( $input ) ); | ||
} | ||
|
||
public function data_sanitize_locale_name_returns_empty_string() { | ||
return array( | ||
// array( input ) | ||
array( '$<>' ), | ||
array( '/$$$%%\\)' ), | ||
array( '....' ), | ||
array( '@///' ), | ||
); | ||
} | ||
} |