@@ -747,78 +747,34 @@ public function test_image_prioritizer_validate_background_image_url( Closure $s
747747 *
748748 * @return array<string, mixed>
749749 */
750- public function data_provider_to_test_image_prioritizer_filter_store_url_metric_validity (): array {
750+ public function data_provider_to_test_image_prioritizer_filter_url_metric_data_pre_storage (): array {
751751 return array (
752- 'pass_through_true ' => array (
753- 'set_up ' => static function ( array $ sample_url_metric_data ): array {
754- $ url_metric = new OD_Strict_URL_Metric ( $ sample_url_metric_data );
755- return array ( true , $ url_metric );
756- },
757- 'assert ' => function ( $ value ): void {
758- $ this ->assertTrue ( $ value );
759- },
760- ),
761-
762- 'pass_through_false ' => array (
763- 'set_up ' => static function ( array $ sample_url_metric_data ): array {
764- $ url_metric = new OD_Strict_URL_Metric ( $ sample_url_metric_data );
765- return array ( false , $ url_metric );
766- },
767- 'assert ' => function ( $ value ): void {
768- $ this ->assertFalse ( $ value );
769- },
770- ),
771-
772- 'pass_through_truthy_string ' => array (
773- 'set_up ' => static function ( array $ sample_url_metric_data ): array {
774- $ url_metric = new OD_Strict_URL_Metric ( $ sample_url_metric_data );
775- return array ( 'so true ' , $ url_metric );
776- },
777- 'assert ' => function ( $ value ): void {
778- $ this ->assertTrue ( $ value );
779- },
780- ),
781-
782- 'pass_through_falsy_string ' => array (
783- 'set_up ' => static function ( array $ sample_url_metric_data ): array {
784- $ url_metric = new OD_Strict_URL_Metric ( $ sample_url_metric_data );
785- return array ( '' , $ url_metric );
786- },
787- 'assert ' => function ( $ value ): void {
788- $ this ->assertFalse ( $ value );
789- },
790- ),
791-
792- 'pass_through_wp_error ' => array (
793- 'set_up ' => static function ( array $ sample_url_metric_data ): array {
794- $ url_metric = new OD_Strict_URL_Metric ( $ sample_url_metric_data );
795- return array ( new WP_Error ( 'bad ' , 'Evil ' ), $ url_metric );
796- },
797- 'assert ' => function ( $ value ): void {
798- $ this ->assertInstanceOf ( WP_Error::class, $ value );
799- $ this ->assertSame ( 'bad ' , $ value ->get_error_code () );
800- },
801- ),
802-
803- 'invalid_external_bg_image ' => array (
804- 'set_up ' => static function ( array $ sample_url_metric_data ): array {
805- $ sample_url_metric_data ['lcpElementExternalBackgroundImage ' ] = array (
752+ 'invalid_external_bg_image ' => array (
753+ 'set_up ' => static function ( array $ url_metric_data ): array {
754+ $ url_metric_data ['lcpElementExternalBackgroundImage ' ] = array (
806755 'url ' => 'https://bad-origin.example.com/image.jpg ' ,
807756 'tag ' => 'DIV ' ,
808757 'id ' => null ,
809758 'class ' => null ,
810759 );
811- $ url_metric = new OD_Strict_URL_Metric ( $ sample_url_metric_data );
812- return array ( true , $ url_metric );
760+ $ url_metric_data ['viewport ' ]['width ' ] = 10101 ;
761+ $ url_metric_data ['viewport ' ]['height ' ] = 20202 ;
762+ return $ url_metric_data ;
813763 },
814- 'assert ' => function ( $ value , OD_Strict_URL_Metric $ url_metric ): void {
815- $ this ->assertTrue ( $ value );
816- $ this ->assertNull ( $ url_metric ->get ( 'lcpElementExternalBackgroundImage ' ) );
764+ 'assert ' => function ( array $ url_metric_data ): void {
765+ $ this ->assertArrayNotHasKey ( 'lcpElementExternalBackgroundImage ' , $ url_metric_data );
766+ $ this ->assertSame (
767+ array (
768+ 'width ' => 10101 ,
769+ 'height ' => 20202 ,
770+ ),
771+ $ url_metric_data ['viewport ' ]
772+ );
817773 },
818774 ),
819775
820- 'valid_external_bg_image ' => array (
821- 'set_up ' => static function ( array $ sample_url_metric_data ): array {
776+ 'valid_external_bg_image ' => array (
777+ 'set_up ' => static function ( array $ url_metric_data ): array {
822778 $ image_url = home_url ( '/good.jpg ' );
823779
824780 add_filter (
@@ -843,46 +799,54 @@ static function ( $pre, $parsed_args, $url ) use ( $image_url ) {
843799 3
844800 );
845801
846- $ sample_url_metric_data ['lcpElementExternalBackgroundImage ' ] = array (
802+ $ url_metric_data ['lcpElementExternalBackgroundImage ' ] = array (
847803 'url ' => $ image_url ,
848804 'tag ' => 'DIV ' ,
849805 'id ' => null ,
850806 'class ' => null ,
851807 );
852- $ url_metric = new OD_Strict_URL_Metric ( $ sample_url_metric_data );
853- return array ( true , $ url_metric );
808+
809+ $ url_metric_data ['viewport ' ]['width ' ] = 30303 ;
810+ $ url_metric_data ['viewport ' ]['height ' ] = 40404 ;
811+ return $ url_metric_data ;
854812 },
855- 'assert ' => function ( $ value , OD_Strict_URL_Metric $ url_metric ): void {
856- $ this ->assertTrue ( $ value );
857- $ this ->assertIsArray ( $ url_metric -> get ( 'lcpElementExternalBackgroundImage ' ) );
813+ 'assert ' => function ( array $ url_metric_data ): void {
814+ $ this ->assertArrayHasKey ( ' lcpElementExternalBackgroundImage ' , $ url_metric_data );
815+ $ this ->assertIsArray ( $ url_metric_data [ 'lcpElementExternalBackgroundImage ' ] );
858816 $ this ->assertSame (
859817 array (
860818 'url ' => home_url ( '/good.jpg ' ),
861819 'tag ' => 'DIV ' ,
862820 'id ' => null ,
863821 'class ' => null ,
864822 ),
865- $ url_metric ->get ( 'lcpElementExternalBackgroundImage ' )
823+ $ url_metric_data ['lcpElementExternalBackgroundImage ' ]
824+ );
825+ $ this ->assertSame (
826+ array (
827+ 'width ' => 30303 ,
828+ 'height ' => 40404 ,
829+ ),
830+ $ url_metric_data ['viewport ' ]
866831 );
867832 },
868833 ),
869834 );
870835 }
871836
872837 /**
873- * Tests image_prioritizer_filter_store_url_metric_validity ().
838+ * Tests image_prioritizer_filter_url_metric_data_pre_storage ().
874839 *
875- * @dataProvider data_provider_to_test_image_prioritizer_filter_store_url_metric_validity
840+ * @dataProvider data_provider_to_test_image_prioritizer_filter_url_metric_data_pre_storage
876841 *
877- * @covers ::image_prioritizer_filter_store_url_metric_validity
842+ * @covers ::image_prioritizer_filter_url_metric_data_pre_storage
878843 * @covers ::image_prioritizer_validate_background_image_url
879844 */
880- public function test_image_prioritizer_filter_store_url_metric_validity ( Closure $ set_up , Closure $ assert ): void {
881- $ sample_url_metric_data = $ this ->get_sample_url_metric ( array () )->jsonSerialize ();
882- list ( $ validity , $ url_metric ) = $ set_up ( $ sample_url_metric_data );
845+ public function test_image_prioritizer_filter_url_metric_data_pre_storage ( Closure $ set_up , Closure $ assert ): void {
846+ $ url_metric_data = $ set_up ( $ this ->get_sample_url_metric ( array () )->jsonSerialize () );
883847
884- $ validity = image_prioritizer_filter_store_url_metric_validity ( $ validity , $ url_metric );
885- $ assert ( $ validity , $ url_metric );
848+ $ url_metric_data = image_prioritizer_filter_url_metric_data_pre_storage ( $ url_metric_data );
849+ $ assert ( $ url_metric_data );
886850 }
887851
888852 /**
0 commit comments