@@ -467,6 +467,63 @@ public function test_image_prioritizer_add_element_item_schema_properties_inputs
467
467
}
468
468
}
469
469
470
+ /**
471
+ * Data provider.
472
+ *
473
+ * @return array<string, mixed>
474
+ */
475
+ public function data_provider_to_test_image_prioritizer_validate_background_image_url (): array {
476
+ return array (
477
+ 'url_parse_error ' => array (
478
+ 'set_up ' => static function (): string {
479
+ return 'https:///www.example.com ' ;
480
+ },
481
+ 'expect_error ' => 'background_image_url_lacks_host ' ,
482
+ ),
483
+ 'url_no_host ' => array (
484
+ 'set_up ' => static function (): string {
485
+ return '/foo/bar?baz=1 ' ;
486
+ },
487
+ 'expect_error ' => 'background_image_url_lacks_host ' ,
488
+ ),
489
+ 'url_disallowed_origin ' => array (
490
+ 'set_up ' => static function (): string {
491
+ return 'https://bad.example.com/foo.jpg ' ;
492
+ },
493
+ 'expect_error ' => 'disallowed_background_image_url_host ' ,
494
+ ),
495
+ // TODO: Try uploading image attachment and have it point to a CDN.
496
+ // TODO: Try a URL that returns a non image Content-Type.
497
+ );
498
+ }
499
+
500
+ /**
501
+ * Tests image_prioritizer_validate_background_image_url().
502
+ *
503
+ * @covers ::image_prioritizer_validate_background_image_url
504
+ *
505
+ * @dataProvider data_provider_to_test_image_prioritizer_validate_background_image_url
506
+ */
507
+ public function test_image_prioritizer_validate_background_image_url ( Closure $ set_up , ?string $ expect_error ): void {
508
+ $ url = $ set_up ();
509
+ $ validity = image_prioritizer_validate_background_image_url ( $ url );
510
+ if ( null === $ expect_error ) {
511
+ $ this ->assertTrue ( $ validity );
512
+ } else {
513
+ $ this ->assertInstanceOf ( WP_Error::class, $ validity );
514
+ $ this ->assertSame ( $ expect_error , $ validity ->get_error_code () );
515
+ }
516
+ }
517
+
518
+ /**
519
+ * Tests image_prioritizer_filter_store_url_metric_validity().
520
+ *
521
+ * @covers ::image_prioritizer_filter_store_url_metric_validity
522
+ */
523
+ public function test_image_prioritizer_filter_store_url_metric_validity (): void {
524
+ $ this ->markTestIncomplete ();
525
+ }
526
+
470
527
/**
471
528
* Test image_prioritizer_get_video_lazy_load_script.
472
529
*
0 commit comments