Changeset 47122 for trunk/tests/phpunit/tests/ajax/Compression.php
- Timestamp:
- 01/29/2020 12:43:23 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/ajax/Compression.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 compression test functionality9 * Testing Ajax compression test functionality. 10 10 * 11 11 * @package WordPress … … 22 22 $this->logout(); 23 23 24 // Set up a default request 24 // Set up a default request. 25 25 $_GET['test'] = 1; 26 26 27 // Make the request 27 // Make the request. 28 28 $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); 29 29 $this->_handleAjax( 'wp-compression-test' ); … … 35 35 public function test_text() { 36 36 37 // Become an administrator 38 $this->_setRole( 'administrator' ); 39 40 // Set up a default request 37 // Become an administrator. 38 $this->_setRole( 'administrator' ); 39 40 // Set up a default request. 41 41 $_GET['test'] = 1; 42 42 43 // Make the request 43 // Make the request. 44 44 try { 45 45 $this->_handleAjax( 'wp-compression-test' ); … … 48 48 } 49 49 50 // Ensure we found the right match 50 // Ensure we found the right match. 51 51 $this->assertContains( 'wpCompressionTest', $this->_last_response ); 52 52 } … … 61 61 } 62 62 63 // Become an administrator 64 $this->_setRole( 'administrator' ); 65 66 // Set up a default request 63 // Become an administrator. 64 $this->_setRole( 'administrator' ); 65 66 // Set up a default request. 67 67 $_GET['test'] = 2; 68 68 $_SERVER['HTTP_ACCEPT_ENCODING'] = 'deflate'; 69 69 70 // Make the request 70 // Make the request. 71 71 try { 72 72 $this->_handleAjax( 'wp-compression-test' ); … … 75 75 } 76 76 77 // Ensure we found the right match 77 // Ensure we found the right match. 78 78 $this->assertContains( 'wpCompressionTest', gzinflate( $this->_last_response ) ); 79 79 } … … 88 88 } 89 89 90 // Become an administrator 91 $this->_setRole( 'administrator' ); 92 93 // Set up a default request 90 // Become an administrator. 91 $this->_setRole( 'administrator' ); 92 93 // Set up a default request. 94 94 $_GET['test'] = 2; 95 95 $_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip'; 96 96 97 // Make the request 97 // Make the request. 98 98 try { 99 99 $this->_handleAjax( 'wp-compression-test' ); … … 102 102 } 103 103 104 // Ensure we found the right match 104 // Ensure we found the right match. 105 105 $this->assertContains( 'wpCompressionTest', $this->_gzdecode( $this->_last_response ) ); 106 106 } … … 111 111 public function test_unknown_encoding() { 112 112 113 // Become an administrator 114 $this->_setRole( 'administrator' ); 115 116 // Set up a default request 113 // Become an administrator. 114 $this->_setRole( 'administrator' ); 115 116 // Set up a default request. 117 117 $_GET['test'] = 2; 118 118 $_SERVER['HTTP_ACCEPT_ENCODING'] = 'unknown'; 119 119 120 // Make the request 120 // Make the request. 121 121 $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); 122 122 $this->_handleAjax( 'wp-compression-test' ); … … 128 128 public function test_set_yes() { 129 129 130 // Become an administrator 131 $this->_setRole( 'administrator' ); 132 133 // Set up a default request 130 // Become an administrator. 131 $this->_setRole( 'administrator' ); 132 133 // Set up a default request. 134 134 $_GET['test'] = 'yes'; 135 135 136 // Set the option to false 136 // Set the option to false. 137 137 update_site_option( 'can_compress_scripts', 0 ); 138 138 139 // Make the request 140 try { 141 $this->_handleAjax( 'wp-compression-test' ); 142 } catch ( WPAjaxDieStopException $e ) { 143 unset( $e ); 144 } 145 146 // Check the site option is not changed due to lack of nonce 139 // Make the request. 140 try { 141 $this->_handleAjax( 'wp-compression-test' ); 142 } catch ( WPAjaxDieStopException $e ) { 143 unset( $e ); 144 } 145 146 // Check the site option is not changed due to lack of nonce. 147 147 $this->assertEquals( 0, get_site_option( 'can_compress_scripts' ) ); 148 148 149 // Add a nonce 149 // Add a nonce. 150 150 $_GET['_ajax_nonce'] = wp_create_nonce( 'update_can_compress_scripts' ); 151 151 152 // Retry the request 153 try { 154 $this->_handleAjax( 'wp-compression-test' ); 155 } catch ( WPAjaxDieStopException $e ) { 156 unset( $e ); 157 } 158 159 // Check the site option is changed 152 // Retry the request. 153 try { 154 $this->_handleAjax( 'wp-compression-test' ); 155 } catch ( WPAjaxDieStopException $e ) { 156 unset( $e ); 157 } 158 159 // Check the site option is changed. 160 160 $this->assertEquals( 1, get_site_option( 'can_compress_scripts' ) ); 161 161 } … … 166 166 public function test_set_no() { 167 167 168 // Become an administrator 169 $this->_setRole( 'administrator' ); 170 171 // Set up a default request 168 // Become an administrator. 169 $this->_setRole( 'administrator' ); 170 171 // Set up a default request. 172 172 $_GET['test'] = 'no'; 173 173 174 // Set the option to true 174 // Set the option to true. 175 175 update_site_option( 'can_compress_scripts', 1 ); 176 176 177 // Make the request 178 try { 179 $this->_handleAjax( 'wp-compression-test' ); 180 } catch ( WPAjaxDieStopException $e ) { 181 unset( $e ); 182 } 183 184 // Check the site option is not changed due to lack of nonce 177 // Make the request. 178 try { 179 $this->_handleAjax( 'wp-compression-test' ); 180 } catch ( WPAjaxDieStopException $e ) { 181 unset( $e ); 182 } 183 184 // Check the site option is not changed due to lack of nonce. 185 185 $this->assertEquals( 1, get_site_option( 'can_compress_scripts' ) ); 186 186 187 // Add a nonce 187 // Add a nonce. 188 188 $_GET['_ajax_nonce'] = wp_create_nonce( 'update_can_compress_scripts' ); 189 189 190 // Retry the request 191 try { 192 $this->_handleAjax( 'wp-compression-test' ); 193 } catch ( WPAjaxDieStopException $e ) { 194 unset( $e ); 195 } 196 197 // Check the site option is changed 190 // Retry the request. 191 try { 192 $this->_handleAjax( 'wp-compression-test' ); 193 } catch ( WPAjaxDieStopException $e ) { 194 unset( $e ); 195 } 196 197 // Check the site option is changed. 198 198 $this->assertEquals( 0, get_site_option( 'can_compress_scripts' ) ); 199 199 } … … 207 207 protected function _gzdecode( $encoded_data ) { 208 208 209 // Save the encoded data to a temp file 209 // Save the encoded data to a temp file. 210 210 $file = wp_tempnam( 'gzdecode' ); 211 211 file_put_contents( $file, $encoded_data ); 212 212 213 // Flush it to the output buffer and delete the temp file 213 // Flush it to the output buffer and delete the temp file. 214 214 ob_start(); 215 215 readgzfile( $file ); 216 216 unlink( $file ); 217 217 218 // Save the data stop buffering 218 // Save the data stop buffering. 219 219 $data = ob_get_clean(); 220 220 221 // Done 221 // Done. 222 222 return $data; 223 223 }
Note: See TracChangeset
for help on using the changeset viewer.