- Timestamp:
- 12/14/2021 06:22:07 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-global-styles-controller.php
r52374 r52376 94 94 /** 95 95 * @covers WP_REST_Global_Styles_Controller::register_routes 96 * @ticket 54596 96 97 */ 97 98 public function test_register_routes() { 98 99 $routes = rest_get_server()->get_routes(); 99 $this->assertArrayHasKey( '/wp/v2/global-styles/(?P<id>[\/\w-]+)', $routes ); 100 $this->assertCount( 2, $routes['/wp/v2/global-styles/(?P<id>[\/\w-]+)'] ); 101 $this->assertArrayHasKey( '/wp/v2/global-styles/themes/(?P<stylesheet>[^.\/]+(?:\/[^.\/]+)?)', $routes ); 102 $this->assertCount( 1, $routes['/wp/v2/global-styles/themes/(?P<stylesheet>[^.\/]+(?:\/[^.\/]+)?)'] ); 100 $this->assertArrayHasKey( 101 '/wp/v2/global-styles/(?P<id>[\/\s%\w\.\(\)\[\]\@_\-]+)', 102 $routes, 103 'Single global style based on the given ID route does not exist' 104 ); 105 $this->assertCount( 106 2, 107 $routes['/wp/v2/global-styles/(?P<id>[\/\s%\w\.\(\)\[\]\@_\-]+)'], 108 'Single global style based on the given ID route does not have exactly two elements' 109 ); 110 $this->assertArrayHasKey( 111 '/wp/v2/global-styles/themes/(?P<stylesheet>[\/\s%\w\.\(\)\[\]\@_\-]+)', 112 $routes, 113 'Theme global styles route does not exist' 114 ); 115 $this->assertCount( 116 1, 117 $routes['/wp/v2/global-styles/themes/(?P<stylesheet>[\/\s%\w\.\(\)\[\]\@_\-]+)'], 118 'Theme global styles route does not have exactly one element' 119 ); 103 120 } 104 121 … … 133 150 } 134 151 135 136 152 /** 137 153 * @covers WP_REST_Global_Styles_Controller::get_theme_item … … 146 162 147 163 /** 148 * @covers WP_REST_Global_Styles_Controller::get_theme_item 149 */ 150 public function test_get_theme_item() { 151 wp_set_current_user( self::$admin_id ); 152 $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/themes/tt1-blocks' ); 164 * @dataProvider data_get_theme_item_invalid_theme_dirname 165 * @covers WP_REST_Global_Styles_Controller::get_theme_item 166 * @ticket 54596 167 */ 168 public function test_get_theme_item_invalid_theme_dirname( $theme_dirname ) { 169 wp_set_current_user( self::$admin_id ); 170 switch_theme( $theme_dirname ); 171 172 $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/themes/' . $theme_dirname ); 173 $response = rest_get_server()->dispatch( $request ); 174 $this->assertErrorResponse( 'rest_no_route', $response, 404 ); 175 } 176 177 /** 178 * Data provider. 179 * 180 * @return array 181 */ 182 public function data_get_theme_item_invalid_theme_dirname() { 183 return array( 184 'with |' => array( 'my|theme' ), 185 'with +' => array( 'my+theme' ), 186 'with {}' => array( 'my{theme}' ), 187 'with #' => array( 'my#theme' ), 188 'with !' => array( 'my!theme' ), 189 'multiple invalid chars' => array( 'mytheme-[_(+@)]#! v4.0' ), 190 ); 191 } 192 193 /** 194 * @dataProvider data_get_theme_item 195 * @covers WP_REST_Global_Styles_Controller::get_theme_item 196 * @ticket 54596 197 */ 198 public function test_get_theme_item( $theme ) { 199 wp_set_current_user( self::$admin_id ); 200 switch_theme( $theme ); 201 202 $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/themes/' . $theme ); 153 203 $response = rest_get_server()->dispatch( $request ); 154 204 $data = $response->get_data(); 155 205 $links = $response->get_links(); 156 $this->assertArrayHasKey( 'settings', $data ); 157 $this->assertArrayHasKey( 'styles', $data ); 158 $this->assertArrayHasKey( 'self', $links ); 159 $this->assertStringContainsString( '/wp/v2/global-styles/themes/tt1-blocks', $links['self'][0]['href'] ); 206 $this->assertArrayHasKey( 'settings', $data, 'Data does not have "settings" key' ); 207 $this->assertArrayHasKey( 'styles', $data, 'Data does not have "styles" key' ); 208 $this->assertArrayHasKey( 'self', $links, 'Links do not have a "self" key' ); 209 $this->assertStringContainsString( '/wp/v2/global-styles/themes/' . $theme, $links['self'][0]['href'] ); 210 } 211 212 /** 213 * Data provider. 214 * 215 * @return array 216 */ 217 public function data_get_theme_item() { 218 return array( 219 'alphabetic chars' => array( 'mytheme' ), 220 'alphanumeric chars' => array( 'mythemev1' ), 221 'space' => array( 'my theme' ), 222 '-' => array( 'my-theme' ), 223 '_' => array( 'my_theme' ), 224 '.' => array( 'mytheme0.1' ), 225 '- and .' => array( 'my-theme-0.1' ), 226 'space and .' => array( 'mytheme v0.1' ), 227 'space, -, _, .' => array( 'my-theme-v0.1' ), 228 '[]' => array( 'my[theme]' ), 229 '()' => array( 'my(theme)' ), 230 '@' => array( 'my@theme' ), 231 ); 160 232 } 161 233
Note: See TracChangeset
for help on using the changeset viewer.