mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
New functions in `media.php`: * `wp_get_attachment_image_srcset_array()` - Returns an array of image candidate string data used to build a `srcset` value for an attachment given an `$attachement_id` and `$size`. * `wp_get_attachment_image_srcset()` - Returns the `srcset` value for an attachment given an `$attachement_id` and `$size`. * `wp_get_attachment_image_sizes()` - Returns the `sizes` value for an attachment given an `$attachement_id` and `$size` and optional arguments used to alter its output. * `wp_make_content_images_responsive()` - A display filter for adding `srcset` and `sizes` to images embedded in content. * `wp_img_add_srcset_and_sizes()` - A utility function used by `wp_make_content_images_responsive()` to add `srcset` and `sizes` to a single `<img>` element. Modifies existing core functions: * Modify `wp_get_attachment_image()` so the HTML returned for an image includes `srcset` and `sizes`. * Modify `get_media_embedded_in_content()` (sup, 3.6 leftover) by adding `<img>` to the list of accepted tags that can be matched in content. This is used in `wp_make_content_images_responsive()` to find all of the images embedded in content before passing them off to `wp_img_add_srcset_and_sizes()`. Tests: * Add a new factory method to `WP_UnitTest_Factory_For_Attachment` named `create_upload_object()` * Adds unit tests * Updates unit tests Props joemcgill, tevko, jaspermdegroot, mdmcginn, barryceelen, peterwilsoncc, fsylum, wonderboymusic, chriscoyier, benjaminpick, jrfnl, #12kingkool68, janhenckens, ryanmarkel, side777, ryelle, wturrell, micahmills, mattbagwell, coliff, DrewAPicture. See #33641. git-svn-id: https://develop.svn.wordpress.org/trunk@34855 602fd350-edb4-49c9-b593-d223f7449a82
271 lines
9.8 KiB
PHP
271 lines
9.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group xmlrpc
|
|
*/
|
|
class Tests_XMLRPC_mw_editPost extends WP_XMLRPC_UnitTestCase {
|
|
|
|
function test_invalid_username_password() {
|
|
$post = array();
|
|
$result = $this->myxmlrpcserver->mw_editPost( array( 1, 'username', 'password', $post ) );
|
|
$this->assertInstanceOf( 'IXR_Error', $result );
|
|
$this->assertEquals( 403, $result->code );
|
|
}
|
|
|
|
function test_edit_own_post() {
|
|
$contributor_id = $this->make_user_by_role( 'contributor' );
|
|
$post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
|
|
$post_id = wp_insert_post( $post );
|
|
|
|
$new_title = 'Post test (updated)';
|
|
$post2 = array( 'title' => $new_title );
|
|
$result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'contributor', 'contributor', $post2 ) );
|
|
$this->assertNotInstanceOf( 'IXR_Error', $result );
|
|
$this->assertTrue($result);
|
|
|
|
$out = get_post( $post_id );
|
|
$this->assertEquals( $new_title, $out->post_title );
|
|
}
|
|
|
|
function test_capable_edit_others_post() {
|
|
$this->make_user_by_role( 'editor' );
|
|
$contributor_id = $this->make_user_by_role( 'contributor' );
|
|
|
|
$post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
|
|
$post_id = wp_insert_post( $post );
|
|
|
|
$new_title = 'Post test (updated)';
|
|
$post2 = array( 'title' => $new_title );
|
|
$result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'editor', 'editor', $post2 ) );
|
|
$this->assertNotInstanceOf( 'IXR_Error', $result );
|
|
$this->assertTrue($result);
|
|
|
|
$out = get_post( $post_id );
|
|
$this->assertEquals( $new_title, $out->post_title );
|
|
}
|
|
|
|
function test_incapable_edit_others_post() {
|
|
$this->make_user_by_role( 'contributor' );
|
|
$author_id = $this->make_user_by_role( 'author' );
|
|
|
|
$original_title = 'Post test';
|
|
$post = array( 'post_title' => $original_title, 'post_author' => $author_id );
|
|
$post_id = wp_insert_post( $post );
|
|
|
|
$new_title = 'Post test (updated)';
|
|
$post2 = array( 'title' => $new_title );
|
|
$result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'contributor', 'contributor', $post2 ) );
|
|
$this->assertInstanceOf( 'IXR_Error', $result );
|
|
$this->assertEquals( 401, $result->code );
|
|
|
|
$out = get_post( $post_id );
|
|
$this->assertEquals( $original_title, $out->post_title );
|
|
}
|
|
|
|
function test_capable_reassign_author() {
|
|
$contributor_id = $this->make_user_by_role( 'contributor' );
|
|
$author_id = $this->make_user_by_role( 'author' );
|
|
$this->make_user_by_role( 'editor' );
|
|
|
|
$post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
|
|
$post_id = wp_insert_post( $post );
|
|
|
|
$post2 = array( 'wp_author_id' => $author_id );
|
|
$result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'editor', 'editor', $post2 ) );
|
|
$this->assertNotInstanceOf( 'IXR_Error', $result );
|
|
$this->assertTrue($result);
|
|
|
|
$out = get_post( $post_id );
|
|
$this->assertEquals( $author_id, $out->post_author );
|
|
}
|
|
|
|
function test_incapable_reassign_author() {
|
|
$contributor_id = $this->make_user_by_role( 'contributor' );
|
|
$author_id = $this->make_user_by_role( 'author' );
|
|
|
|
$post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
|
|
$post_id = wp_insert_post( $post );
|
|
|
|
$post2 = array( 'wp_author_id' => $author_id );
|
|
$result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'contributor', 'contributor', $post2 ) );
|
|
$this->assertInstanceOf( 'IXR_Error', $result );
|
|
$this->assertEquals( 401, $result->code );
|
|
|
|
$out = get_post( $post_id );
|
|
$this->assertEquals( $contributor_id, $out->post_author );
|
|
}
|
|
|
|
/**
|
|
* @ticket 24916
|
|
*/
|
|
function test_capable_reassign_author_to_self() {
|
|
$contributor_id = $this->make_user_by_role( 'contributor' );
|
|
$editor_id = $this->make_user_by_role( 'editor' );
|
|
|
|
$post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
|
|
$post_id = wp_insert_post( $post );
|
|
|
|
$post2 = array( 'wp_author_id' => $editor_id );
|
|
$result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'editor', 'editor', $post2 ) );
|
|
$this->assertNotInstanceOf( 'IXR_Error', $result );
|
|
$this->assertTrue($result);
|
|
|
|
$out = get_post( $post_id );
|
|
$this->assertEquals( $editor_id, $out->post_author );
|
|
}
|
|
|
|
function test_post_thumbnail() {
|
|
add_theme_support( 'post-thumbnails' );
|
|
|
|
$author_id = $this->make_user_by_role( 'author' );
|
|
|
|
$post = array( 'post_title' => 'Post Thumbnail Test', 'post_author' => $author_id );
|
|
$post_id = wp_insert_post( $post );
|
|
|
|
$this->assertEquals( '', get_post_meta( $post_id, '_thumbnail_id', true ) );
|
|
|
|
// create attachment
|
|
$filename = ( DIR_TESTDATA.'/images/a2-small.jpg' );
|
|
$attachment_id = $this->factory->attachment->create_upload_object( $filename, $post_id );
|
|
|
|
// add post thumbnail to post that does not have one
|
|
$post2 = array( 'wp_post_thumbnail' => $attachment_id );
|
|
$result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'author', 'author', $post2 ) );
|
|
$this->assertNotInstanceOf( 'IXR_Error', $result );
|
|
$this->assertEquals( $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) );
|
|
|
|
// edit the post without supplying a post_thumbnail and check that it didn't change
|
|
$post3 = array( 'post_content' => 'Updated post' );
|
|
$result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'author', 'author', $post3 ) );
|
|
$this->assertNotInstanceOf( 'IXR_Error', $result );
|
|
$this->assertEquals( $attachment_id, get_post_meta( $post_id, '_thumbnail_id', true ) );
|
|
|
|
// create another attachment
|
|
$attachment2_id = $this->factory->attachment->create_upload_object( $filename, $post_id );
|
|
|
|
// change the post's post_thumbnail
|
|
$post4 = array( 'wp_post_thumbnail' => $attachment2_id );
|
|
$result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'author', 'author', $post4 ) );
|
|
$this->assertNotInstanceOf( 'IXR_Error', $result );
|
|
$this->assertEquals( $attachment2_id, get_post_meta( $post_id, '_thumbnail_id', true ) );
|
|
|
|
// unset the post's post_thumbnail
|
|
$post5 = array( 'wp_post_thumbnail' => '' );
|
|
$result = $this->myxmlrpcserver->mw_editPost( array($post_id, 'author', 'author', $post5 ) );
|
|
$this->assertNotInstanceOf( 'IXR_Error', $result );
|
|
$this->assertEquals( '', get_post_meta( $post_id, '_thumbnail_id', true ) );
|
|
|
|
remove_theme_support( 'post-thumbnails' );
|
|
}
|
|
|
|
function test_edit_basic_post_info() {
|
|
$contributor_id = $this->make_user_by_role( 'contributor' );
|
|
|
|
$post = array( 'post_title' => 'Title', 'post_content' => 'Content', 'post_excerpt' => 'Excerpt', 'post_author' => $contributor_id );
|
|
$post_id = wp_insert_post( $post );
|
|
|
|
$post2 = array( 'title' => 'New Title', 'post_author' => $contributor_id );
|
|
$result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'contributor', 'contributor', $post2 ) );
|
|
$this->assertNotInstanceOf( 'IXR_Error', $result );
|
|
$this->assertTrue($result);
|
|
|
|
$out = get_post( $post_id );
|
|
$this->assertEquals( $post2['title'], $out->post_title );
|
|
|
|
$post3 = array( 'description' => 'New Content', 'post_author' => $contributor_id );
|
|
$result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'contributor', 'contributor', $post3 ) );
|
|
$this->assertNotInstanceOf( 'IXR_Error', $result );
|
|
$this->assertTrue($result);
|
|
|
|
$out = get_post( $post_id );
|
|
$this->assertEquals( $post2['title'], $out->post_title );
|
|
$this->assertEquals( $post3['description'], $out->post_content );
|
|
|
|
$post4 = array( 'mt_excerpt' => 'New Excerpt', 'post_author' => $contributor_id );
|
|
$result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'contributor', 'contributor', $post4 ) );
|
|
$this->assertNotInstanceOf( 'IXR_Error', $result );
|
|
$this->assertTrue($result);
|
|
|
|
$out = get_post( $post_id );
|
|
$this->assertEquals( $post2['title'], $out->post_title );
|
|
$this->assertEquals( $post3['description'], $out->post_content );
|
|
$this->assertEquals( $post4['mt_excerpt'], $out->post_excerpt );
|
|
}
|
|
|
|
/**
|
|
* @ticket 20662
|
|
*/
|
|
function test_make_post_sticky() {
|
|
$author_id = $this->make_user_by_role( 'editor' );
|
|
|
|
$post = array( 'post_title' => 'Title', 'post_content' => 'Content', 'post_author' => $author_id, 'post_status' => 'publish' );
|
|
$post_id = wp_insert_post( $post );
|
|
|
|
$result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'editor', 'editor', array( 'sticky' => '1' ) ) );
|
|
$this->assertNotInstanceOf( 'IXR_Error', $result );
|
|
$this->assertTrue( $result );
|
|
}
|
|
|
|
// Not allowed since [19914]
|
|
function test_change_post_type() {
|
|
$contributor_id = $this->make_user_by_role( 'contributor' );
|
|
|
|
$post = array( 'post_title' => 'Title', 'post_author' => $contributor_id );
|
|
$post_id = wp_insert_post( $post );
|
|
|
|
$post2 = array( 'post_type' => 'page' );
|
|
$result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'contributor', 'contributor', $post2 ) );
|
|
$this->assertInstanceOf( 'IXR_Error', $result );
|
|
$this->assertEquals( $result->code, 401 );
|
|
}
|
|
|
|
/**
|
|
* @ticket 30429
|
|
*/
|
|
function test_post_date_timezone_conversion() {
|
|
$tz = get_option( 'timezone_string' );
|
|
update_option( 'timezone_string', 'America/New_York' );
|
|
|
|
$editor_id = $this->make_user_by_role( 'editor' );
|
|
|
|
$post_id = $this->factory->post->create( array(
|
|
'post_author' => $editor_id
|
|
) );
|
|
|
|
$date_string = '1984-01-11 05:00:00';
|
|
$result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'editor', 'editor', array(
|
|
'dateCreated' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string, false ) ),
|
|
) ) );
|
|
|
|
$fetched_post = get_post( $post_id );
|
|
|
|
update_option( 'timezone_string', $tz );
|
|
|
|
$this->assertTrue( $result );
|
|
$this->assertEquals( $date_string, $fetched_post->post_date );
|
|
}
|
|
|
|
/**
|
|
* @ticket 16980
|
|
*/
|
|
function test_empty_not_null() {
|
|
$editor_id = $this->make_user_by_role( 'editor' );
|
|
|
|
$post_id = $this->factory->post->create( array(
|
|
'post_title' => 'Title',
|
|
'post_author' => $editor_id,
|
|
'tags_input' => 'taco'
|
|
) );
|
|
|
|
$tags1 = get_the_tags( $post_id );
|
|
$this->assertNotEmpty( $tags1 );
|
|
|
|
$this->myxmlrpcserver->mw_editPost( array( $post_id, 'editor', 'editor', array(
|
|
'mt_keywords' => ''
|
|
) ) );
|
|
|
|
$tags2 = get_the_tags( $post_id );
|
|
$this->assertEmpty( $tags2 );
|
|
}
|
|
}
|