@@ -7,12 +7,12 @@ class ImageTest extends TestCase
77{
88 public function testAltTagEncoding ()
99 {
10- $ this ->assertSame ('<img src="https://storage.flyo.cloud/foo.jpg?format=webp" alt="<h1>hoi</h1>" loading="lazy" decoding="async" /> ' , Image::tag ('foo.jpg ' , '<h1>hoi</h1> ' ));
10+ $ this ->assertSame ('<img src="https://storage.flyo.cloud/foo.jpg?format=webp" alt="<h1>hoi</h1>" loading="lazy" decoding="async" fetchpriority="auto" /> ' , Image::tag ('foo.jpg ' , '<h1>hoi</h1> ' ));
1111 }
1212
1313 public function testDefaultValues ()
1414 {
15- $ this ->assertSame ('src="https://storage.flyo.cloud/foo.png?format=webp" alt="alt" loading="lazy" decoding="async" ' , Image::attributes ('foo.png ' , 'alt ' ));
15+ $ this ->assertSame ('src="https://storage.flyo.cloud/foo.png?format=webp" alt="alt" loading="lazy" decoding="async" fetchpriority="auto" ' , Image::attributes ('foo.png ' , 'alt ' ));
1616 }
1717
1818 public function testExternalOtherSource ()
@@ -31,8 +31,8 @@ public function testFromCaptionButOwnAltTag()
3131 ], 100 , 100 , 'Own Alt Tag ' );
3232
3333 $ this ->assertSame ('https://storage.flyo.cloud/test.jpg/thumb/100x100?format=webp ' , $ image ->getSrc ());
34- $ this ->assertSame ('src="https://storage.flyo.cloud/test.jpg/thumb/100x100?format=webp" alt="Own Alt Tag" loading="lazy" decoding="async" width="100" height="100" ' , $ image ->toAttributes ());
35- $ this ->assertSame ('<img src="https://storage.flyo.cloud/test.jpg/thumb/100x100?format=webp" alt="Own Alt Tag" loading="lazy" decoding="async" width="100" height="100" /> ' , $ image ->toTag ());
34+ $ this ->assertSame ('src="https://storage.flyo.cloud/test.jpg/thumb/100x100?format=webp" alt="Own Alt Tag" loading="lazy" decoding="async" fetchpriority="auto" width="100" height="100" ' , $ image ->toAttributes ());
35+ $ this ->assertSame ('<img src="https://storage.flyo.cloud/test.jpg/thumb/100x100?format=webp" alt="Own Alt Tag" loading="lazy" decoding="async" fetchpriority="auto" width="100" height="100" /> ' , $ image ->toTag ());
3636 }
3737
3838 public function testFromCaptionButOwnAltTagWithEncoding ()
@@ -42,7 +42,7 @@ public function testFromCaptionButOwnAltTagWithEncoding()
4242 ], 100 , 100 , '"Test Encoding" ' );
4343
4444 $ this ->assertSame ('"Test Encoding" ' , $ image ->getAlt ());
45- $ this ->assertSame ('<img src="https://storage.flyo.cloud/test.jpg/thumb/100x100?format=webp" alt=""Test Encoding"" loading="lazy" decoding="async" width="100" height="100" /> ' , $ image ->toTag ());
45+ $ this ->assertSame ('<img src="https://storage.flyo.cloud/test.jpg/thumb/100x100?format=webp" alt=""Test Encoding"" loading="lazy" decoding="async" fetchpriority="auto" width="100" height="100" /> ' , $ image ->toTag ());
4646 }
4747
4848 public function testFromObject ()
@@ -53,8 +53,8 @@ public function testFromObject()
5353 ], 100 , 100 );
5454
5555 $ this ->assertSame ('https://storage.flyo.cloud/test.jpg/thumb/100x100?format=webp ' , $ image ->getSrc ());
56- $ this ->assertSame ('src="https://storage.flyo.cloud/test.jpg/thumb/100x100?format=webp" alt="Test Image" loading="lazy" decoding="async" width="100" height="100" ' , $ image ->toAttributes ());
57- $ this ->assertSame ('<img src="https://storage.flyo.cloud/test.jpg/thumb/100x100?format=webp" alt="Test Image" loading="lazy" decoding="async" width="100" height="100" /> ' , $ image ->toTag ());
56+ $ this ->assertSame ('src="https://storage.flyo.cloud/test.jpg/thumb/100x100?format=webp" alt="Test Image" loading="lazy" decoding="async" fetchpriority="auto" width="100" height="100" ' , $ image ->toAttributes ());
57+ $ this ->assertSame ('<img src="https://storage.flyo.cloud/test.jpg/thumb/100x100?format=webp" alt="Test Image" loading="lazy" decoding="async" fetchpriority="auto" width="100" height="100" /> ' , $ image ->toTag ());
5858 }
5959
6060 public function testImageConstructor ()
@@ -68,14 +68,14 @@ public function testImageOptions()
6868 {
6969 $ tag = Image::tag ('test.jpg ' , 'Test Image ' , 100 , 200 , 'png ' , 'auto ' , 'sync ' , ['class ' => 'img-fluid ' , 'foo ' => 1 ]);
7070
71- $ this ->assertEquals ('<img src="https://storage.flyo.cloud/test.jpg/thumb/100x200?format=png" alt="Test Image" loading="eager" decoding="sync" width="100" height="200" class="img-fluid" foo="1" /> ' , $ tag );
71+ $ this ->assertEquals ('<img src="https://storage.flyo.cloud/test.jpg/thumb/100x200?format=png" alt="Test Image" loading="eager" decoding="sync" fetchpriority="auto" width="100" height="200" class="img-fluid" foo="1" /> ' , $ tag );
7272 }
7373
7474 public function testImageTag ()
7575 {
7676 $ tag = Image::tag ('test.jpg ' , 'Test Image ' , 100 , 200 , 'png ' , 'auto ' , 'sync ' );
7777
78- $ this ->assertEquals ('<img src="https://storage.flyo.cloud/test.jpg/thumb/100x200?format=png" alt="Test Image" loading="eager" decoding="sync" width="100" height="200" /> ' , $ tag );
78+ $ this ->assertEquals ('<img src="https://storage.flyo.cloud/test.jpg/thumb/100x200?format=png" alt="Test Image" loading="eager" decoding="sync" fetchpriority="auto" width="100" height="200" /> ' , $ tag );
7979 }
8080
8181 public function testSourceOnly ()
@@ -85,6 +85,38 @@ public function testSourceOnly()
8585 $ this ->assertSame ('https://storage.flyo.cloud/foobar.jpg ' , Image::source ('foobar.jpg ' , null , null , 'jpg ' ));
8686 }
8787
88+ public function testFetchpriority ()
89+ {
90+ // Test default value (auto)
91+ $ image = new Image ('test.jpg ' , 'Test Image ' );
92+ $ this ->assertSame ('auto ' , $ image ->getFetchpriority ());
93+
94+ // Test high priority
95+ $ image = new Image ('test.jpg ' , 'Test Image ' , null , null , 'webp ' , 'lazy ' , 'async ' , 'high ' );
96+ $ this ->assertSame ('high ' , $ image ->getFetchpriority ());
97+
98+ // Test low priority
99+ $ image = new Image ('test.jpg ' , 'Test Image ' , null , null , 'webp ' , 'lazy ' , 'async ' , 'low ' );
100+ $ this ->assertSame ('low ' , $ image ->getFetchpriority ());
101+
102+ // Test invalid value falls back to auto
103+ $ image = new Image ('test.jpg ' , 'Test Image ' , null , null , 'webp ' , 'lazy ' , 'async ' , 'invalid ' );
104+ $ this ->assertSame ('auto ' , $ image ->getFetchpriority ());
105+
106+ // Test setter
107+ $ image = new Image ('test.jpg ' , 'Test Image ' );
108+ $ image ->setFetchpriority ('high ' );
109+ $ this ->assertSame ('high ' , $ image ->getFetchpriority ());
110+
111+ // Test in tag output with high priority
112+ $ tag = Image::tag ('test.jpg ' , 'Test Image ' , 100 , 100 , 'webp ' , 'lazy ' , 'async ' , [], 'high ' );
113+ $ this ->assertStringContainsString ('fetchpriority="high" ' , $ tag );
114+
115+ // Test in attributes output with low priority
116+ $ attributes = Image::attributes ('test.jpg ' , 'Test Image ' , 100 , 100 , 'webp ' , 'lazy ' , 'async ' , 'low ' );
117+ $ this ->assertStringContainsString ('fetchpriority="low" ' , $ attributes );
118+ }
119+
88120 /*
89121 public function testGetSrc()
90122 {
0 commit comments