| 610 | |
| 611 | /** |
| 612 | *测试确保原始作者的autosave在被第二作者接管后不会覆盖更改。 |
| 613 | * |
| 614 | *@门票55659 |
| 615 | */ |
| 616 | 公共函数test_rest_autosave_draft_post_locked_to_different_author(){ |
| 617 | |
| 618 | //由编辑创建帖子。 |
| 619 | $post_data=数组( |
| 620 | “post_content”=>“测试帖子内容”, |
| 621 | “post_title”=>“测试文章标题”, |
| 622 | “post_excerpt”=>“测试后摘录”, |
| 623 | “post_author”=>自我::$editor_id, |
| 624 | “post_status”=>“草稿”, |
| 625 | ); |
| 626 | $post_id=wp_insert_post($post_data); |
| 627 | |
| 628 | //将post锁设置为contributor,模拟接管post。 |
| 629 | wp_set_current_user(自身::$contribor_id); |
| 630 | wp_set_post_lock($post_id); |
| 631 | |
| 632 | //使用参与者的新数据更新帖子。 |
| 633 | $updated_post_data=数组( |
| 634 | “ID”=>$post_ID, |
| 635 | “post_content”=>“来自参与者的新帖子内容”, |
| 636 | “post_title”=>“新建帖子标题”, |
| 637 | ); |
| 638 | wp_update_post($更新后数据); |
| 639 | |
| 640 | //将当前用户设置为编辑器,并使用一些新数据启动自动保存。 |
| 641 | wp_set_current_user(自身::$editor_id); |
| 642 | $autosave_data=数组( |
| 643 | 'id'=>$post_id, |
| 644 | “content”=>“更新的文章内容”, |
| 645 | “摘录”=>“要测试的新摘录”, |
| 646 | 'title'=>$post_data['post_title'], |
| 647 | ); |
| 648 | |
| 649 | //像古腾堡那样,通过REST API启动自动保存。 |
| 650 | $request=新的WP_REST_request('POST','/WP/v2/posts/'.self::$POST_id.'/autosaves'); |
| 651 | $request->add_header('content-type','application/json'); |
| 652 | $request->set_body(wp_json_encode($autosave_data)); |
| 653 | |
| 654 | $response=rest_get_server()->分派($request); |
| 655 | $new_data=$response->get_data(); |
| 656 | |
| 657 | //测试帖子的当前版本。 |
| 658 | $current_post=获取post($post_id); |
| 659 | |
| 660 | //来自autosave的新数据应将其父ID设置为原始post ID。 |
| 661 | $this->assertSame($post_id,$new_data['parent']); |
| 662 | |
| 663 | //文章标题和内容仍然应该是作者的更新版本。 |
| 664 | $this->assertSame($current_post->post_title,$updated_post_data['post_title']); |
| 665 | $this->assertSame($current_post->post_content,$updated_post_data['post_content']); |
| 666 | |
| 667 | //摘录本应保持不变。 |
| 668 | $this->assertSame($current_post->post_excerpt,$post_data['post_excherpt']); |
| 669 | |
| 670 | $autosave_post=wp_get_post_autosave($post_id); |
| 671 | |
| 672 | //有更改。 |
| 673 | $this->assertSame($autosave_data['content'],$autosave post->post_content); |
| 674 | |
| 675 | wp_delete_post($post_id); |
| 676 | } |