Changeset 47122 for trunk/tests/phpunit/tests/ajax/Autosave.php
- Timestamp:
- 01/29/2020 12:43:23 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/ajax/Autosave.php
r46586 r47122 2 2 3 3 /** 4 * Admin ajax functions to be tested4 * Admin Ajax functions to be tested. 5 5 */ 6 6 require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' ); 7 7 8 8 /** 9 * Testing ajax save draft functionality9 * Testing Ajax save draft functionality. 10 10 * 11 11 * @package WordPress … … 44 44 public function setUp() { 45 45 parent::setUp(); 46 // Set a user so the $post has 'post_author' 46 // Set a user so the $post has 'post_author'. 47 47 wp_set_current_user( self::$admin_id ); 48 48 } … … 54 54 */ 55 55 public function test_autosave_post() { 56 // The original post_author 56 // The original post_author. 57 57 wp_set_current_user( self::$admin_id ); 58 58 59 // Set up the $_POST request 59 // Set up the $_POST request. 60 60 $md5 = md5( uniqid() ); 61 61 $_POST = array( … … 72 72 ); 73 73 74 // Make the request 74 // Make the request. 75 75 try { 76 76 $this->_handleAjax( 'heartbeat' ); … … 79 79 } 80 80 81 // Get the response, it is in heartbeat's response 81 // Get the response, it is in heartbeat's response. 82 82 $response = json_decode( $this->_last_response, true ); 83 83 84 // Ensure everything is correct 84 // Ensure everything is correct. 85 85 $this->assertNotEmpty( $response['wp_autosave'] ); 86 86 $this->assertTrue( $response['wp_autosave']['success'] ); 87 87 88 // Check that the edit happened 88 // Check that the edit happened. 89 89 $post = get_post( self::$post_id ); 90 90 $this->assertGreaterThanOrEqual( 0, strpos( self::$post->post_content, $md5 ) ); … … 97 97 */ 98 98 public function test_autosave_locked_post() { 99 // Lock the post to another user 99 // Lock the post to another user. 100 100 wp_set_current_user( self::$editor_id ); 101 101 wp_set_post_lock( self::$post_id ); … … 103 103 wp_set_current_user( self::$admin_id ); 104 104 105 // Ensure post is locked 105 // Ensure post is locked. 106 106 $this->assertEquals( self::$editor_id, wp_check_post_lock( self::$post_id ) ); 107 107 108 // Set up the $_POST request 108 // Set up the $_POST request. 109 109 $md5 = md5( uniqid() ); 110 110 $_POST = array( … … 121 121 ); 122 122 123 // Make the request 123 // Make the request. 124 124 try { 125 125 $this->_handleAjax( 'heartbeat' ); … … 130 130 $response = json_decode( $this->_last_response, true ); 131 131 132 // Ensure everything is correct 132 // Ensure everything is correct. 133 133 $this->assertNotEmpty( $response['wp_autosave'] ); 134 134 $this->assertTrue( $response['wp_autosave']['success'] ); 135 135 136 // Check that the original post was NOT edited 136 // Check that the original post was NOT edited. 137 137 $post = get_post( self::$post_id ); 138 138 $this->assertFalse( strpos( $post->post_content, $md5 ) ); 139 139 140 // Check if the autosave post was created 140 // Check if the autosave post was created. 141 141 $autosave = wp_get_post_autosave( self::$post_id, get_current_user_id() ); 142 142 $this->assertNotEmpty( $autosave ); … … 153 153 wp_set_current_user( self::$admin_id ); 154 154 155 // Set up the $_POST request 155 // Set up the $_POST request. 156 156 $_POST = array( 157 157 'action' => 'heartbeat', … … 165 165 ); 166 166 167 // Make the request 167 // Make the request. 168 168 try { 169 169 $this->_handleAjax( 'heartbeat' );
Note: See TracChangeset
for help on using the changeset viewer.