@@ -1975,37 +1975,40 @@ public function test_font_files_preloading( $theme_slug, $expected_urls, $html =
1975
1975
$ html .= '</head><body></body></html> ' ;
1976
1976
}
1977
1977
1978
- $ dom = Document::fromHtml ( $ html , Options::DEFAULTS );
1979
- $ error_codes = [];
1980
- $ sanitizer = new AMP_Style_Sanitizer (
1981
- $ dom ,
1982
- [
1983
- 'use_document_element ' => true ,
1984
- ]
1985
- );
1986
- $ sanitizer ->sanitize ();
1987
- $ this ->assertEquals ( [], $ error_codes );
1978
+ // Do the assertions twice in order to ensure that preloads are still added when the CSS is cached.
1979
+ foreach ( [ 'false ' , 'true ' ] as $ is_cached ) {
1980
+ $ dom = Document::fromHtml ( $ html , Options::DEFAULTS );
1981
+ $ error_codes = [];
1982
+ $ sanitizer = new AMP_Style_Sanitizer (
1983
+ $ dom ,
1984
+ [
1985
+ 'use_document_element ' => true ,
1986
+ ]
1987
+ );
1988
+ $ sanitizer ->sanitize ();
1989
+ $ this ->assertEquals ( [], $ error_codes , "Is cached: $ is_cached " );
1988
1990
1989
- $ link_elements = $ dom ->getElementsByTagName ( 'link ' );
1990
- $ link_elements_count = $ link_elements ->length ;
1991
+ $ link_elements = $ dom ->getElementsByTagName ( 'link ' );
1992
+ $ link_elements_count = $ link_elements ->length ;
1991
1993
1992
- $ actual_urls = array_map (
1993
- static function ( Element $ link_element ) {
1994
- return $ link_element ->getAttribute ( 'href ' );
1995
- },
1996
- iterator_to_array ( $ link_elements )
1997
- );
1994
+ $ actual_urls = array_map (
1995
+ static function ( Element $ link_element ) {
1996
+ return $ link_element ->getAttribute ( 'href ' );
1997
+ },
1998
+ iterator_to_array ( $ link_elements )
1999
+ );
1998
2000
1999
- $ this ->assertEqualSets ( $ expected_urls , $ actual_urls );
2001
+ $ this ->assertEqualSets ( $ expected_urls , $ actual_urls, " Is cached: $ is_cached " );
2000
2002
2001
- for ( $ i = 0 ; $ i < $ link_elements_count ; $ i ++ ) {
2002
- $ this ->assertStringEndsWith (
2003
- $ expected_urls [ $ i ],
2004
- $ link_elements ->item ( $ i )->getAttribute ( 'href ' )
2005
- );
2006
- $ this ->assertEquals ( $ link_elements ->item ( $ i )->getAttribute ( 'rel ' ), 'preload ' );
2007
- $ this ->assertEquals ( $ link_elements ->item ( $ i )->getAttribute ( 'as ' ), 'font ' );
2008
- $ this ->assertEquals ( $ link_elements ->item ( $ i )->getAttribute ( 'crossorigin ' ), '' );
2003
+ for ( $ i = 0 ; $ i < $ link_elements_count ; $ i ++ ) {
2004
+ $ this ->assertStringEndsWith (
2005
+ $ expected_urls [ $ i ],
2006
+ $ link_elements ->item ( $ i )->getAttribute ( 'href ' )
2007
+ );
2008
+ $ this ->assertEquals ( $ link_elements ->item ( $ i )->getAttribute ( 'rel ' ), 'preload ' );
2009
+ $ this ->assertEquals ( $ link_elements ->item ( $ i )->getAttribute ( 'as ' ), 'font ' );
2010
+ $ this ->assertEquals ( $ link_elements ->item ( $ i )->getAttribute ( 'crossorigin ' ), '' );
2011
+ }
2009
2012
}
2010
2013
}
2011
2014
0 commit comments