- Timestamp:
- 02/21/2024 07:24:14 PM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/fonts/font-library/wpFontCollection/getData.php
r57657 r57686 41 41 file_put_contents( $mock_file, wp_json_encode( $config ) ); 42 42 43 $collection = new WP_Font_Collection( $slug, $mock_file ); 43 $collection = new WP_Font_Collection( 44 $slug, 45 array_merge( 46 $config, 47 array( 'font_families' => $mock_file ) 48 ) 49 ); 44 50 $data = $collection->get_data(); 45 51 46 52 $this->assertSame( $slug, $collection->slug, 'The slug should match.' ); 47 $this->assert Same( $expected_data, $data, 'The collection data should match.' );53 $this->assertEqualSetsWithIndex( $expected_data, $data, 'The collection data should match.' ); 48 54 } 49 55 … … 59 65 60 66 self::$mock_collection_data = $config; 61 $collection = new WP_Font_Collection( $slug, 'https://example.com/fonts/mock-font-collection.json' ); 67 $collection = new WP_Font_Collection( 68 $slug, 69 array_merge( 70 $config, 71 array( 72 'font_families' => 'https://example.com/fonts/mock-font-collection.json', 73 ) 74 ) 75 ); 62 76 $data = $collection->get_data(); 63 77 … … 65 79 66 80 $this->assertSame( $slug, $collection->slug, 'The slug should match.' ); 67 $this->assert Same( $expected_data, $data, 'The collection data should match.' );81 $this->assertEqualSetsWithIndex( $expected_data, $data, 'The collection data should match.' ); 68 82 } 69 83 … … 75 89 public function data_create_font_collection() { 76 90 return array( 77 78 91 'font collection with required data' => array( 79 92 'slug' => 'my-collection', … … 186 199 ), 187 200 ), 188 189 201 ); 190 202 } … … 203 215 $this->assertWPError( $data, 'Error is not returned when property is missing or invalid.' ); 204 216 $this->assertSame( 205 $data->get_error_code(),206 217 'font_collection_missing_property', 218 $data->get_error_code(), 207 219 'Incorrect error code when property is missing or invalid.' 208 220 ); … … 244 256 $this->setExpectedIncorrectUsage( 'WP_Font_Collection::load_from_json' ); 245 257 246 $collection = new WP_Font_Collection( 'my-collection', 'non-existing.json' ); 258 $collection = new WP_Font_Collection( 259 'my-collection', 260 array( 261 'name' => 'My collection', 262 'font_families' => 'non-existing.json', 263 ) 264 ); 247 265 $data = $collection->get_data(); 248 266 249 267 $this->assertWPError( $data, 'Error is not returned when invalid file path is provided.' ); 250 268 $this->assertSame( 251 $data->get_error_code(),252 269 'font_collection_json_missing', 270 $data->get_error_code(), 253 271 'Incorrect error code when invalid file path is provided.' 254 272 ); … … 259 277 file_put_contents( $mock_file, 'invalid-json' ); 260 278 261 $collection = new WP_Font_Collection( 'my-collection', $mock_file ); 279 $collection = new WP_Font_Collection( 280 'my-collection', 281 array( 282 'name' => 'Invalid collection', 283 'font_families' => $mock_file, 284 ) 285 ); 262 286 263 287 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Testing error response returned by `load_from_json`, not the underlying error from `wp_json_file_decode`. … … 266 290 $this->assertWPError( $data, 'Error is not returned with invalid json file contents.' ); 267 291 $this->assertSame( 268 $data->get_error_code(),269 292 'font_collection_decode_error', 293 $data->get_error_code(), 270 294 'Incorrect error code with invalid json file contents.' 271 295 ); … … 275 299 $this->setExpectedIncorrectUsage( 'WP_Font_Collection::load_from_json' ); 276 300 277 $collection = new WP_Font_Collection( 'my-collection', 'not-a-url' ); 301 $collection = new WP_Font_Collection( 302 'my-collection', 303 array( 304 'name' => 'Invalid collection', 305 'font_families' => 'not-a-url', 306 ) 307 ); 278 308 $data = $collection->get_data(); 279 309 280 310 $this->assertWPError( $data, 'Error is not returned when invalid url is provided.' ); 281 311 $this->assertSame( 282 $data->get_error_code(),283 312 'font_collection_json_missing', 313 $data->get_error_code(), 284 314 'Incorrect error code when invalid url is provided.' 285 315 ); … … 289 319 add_filter( 'pre_http_request', array( $this, 'mock_request_unsuccessful_response' ), 10, 3 ); 290 320 291 $collection = new WP_Font_Collection( 'my-collection', 'https://example.com/fonts/missing-collection.json' ); 321 $collection = new WP_Font_Collection( 322 'my-collection', 323 array( 324 'name' => 'Missing collection', 325 'font_families' => 'https://example.com/fonts/missing-collection.json', 326 ) 327 ); 292 328 $data = $collection->get_data(); 293 329 … … 296 332 $this->assertWPError( $data, 'Error is not returned when response is unsuccessful.' ); 297 333 $this->assertSame( 298 $data->get_error_code(),299 334 'font_collection_request_error', 300 'Incorrect error code when response is unsuccussful.' 335 $data->get_error_code(), 336 'Incorrect error code when response is unsuccessful.' 301 337 ); 302 338 } … … 305 341 add_filter( 'pre_http_request', array( $this, 'mock_request_invalid_json' ), 10, 3 ); 306 342 307 $collection = new WP_Font_Collection( 'my-collection', 'https://example.com/fonts/invalid-collection.json' ); 343 $collection = new WP_Font_Collection( 344 'my-collection', 345 array( 346 'name' => 'Invalid collection', 347 'font_families' => 'https://example.com/fonts/invalid-collection.json', 348 ) 349 ); 308 350 $data = $collection->get_data(); 309 351 … … 312 354 $this->assertWPError( $data, 'Error is not returned when response is invalid json.' ); 313 355 $this->assertSame( 314 $data->get_error_code(),315 356 'font_collection_decode_error', 357 $data->get_error_code(), 316 358 'Incorrect error code when response is invalid json.' 317 359 );
Note: See TracChangeset
for help on using the changeset viewer.