File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010*/
1111class ImageHasAlt extends BaseRule
1212{
13-
14-
13+
14+
1515 public function id ()
1616 {
1717 return self ::class;
@@ -20,22 +20,15 @@ public function id()
2020 public function check ()
2121 {
2222 foreach ($ this ->getAllElements ('img ' ) as $ img ) {
23- if (!$ img ->hasAttribute ('alt ' )
24- || $ img ->getAttribute ('alt ' ) == ''
25- || $ img ->getAttribute ('alt ' ) == ' ' ) {
26- if (!($ img ->hasAttribute ('role ' )
27- && $ img ->getAttribute ('role ' ) == 'presentation ' )) {
28- $ this ->setIssue ($ img );
29- }
30-
31- else if (!($ img ->hasAttribute ('data-decorative ' )
32- && $ img ->getAttribute ('data-decorative ' ) == 'true ' )) {
23+ if (!$ img ->hasAttribute ('alt ' ) || trim ($ img ->getAttribute ('alt ' )) == '' ) {
24+ if (!($ img ->hasAttribute ('role ' ) && $ img ->getAttribute ('role ' ) == 'presentation ' )
25+ && !($ img ->hasAttribute ('data-decorative ' ) && $ img ->getAttribute ('data-decorative ' ) == 'true ' )) {
3326 $ this ->setIssue ($ img );
3427 }
3528 }
3629 }
37-
30+
3831 return count ($ this ->issues );
3932 }
4033
41- }
34+ }
Original file line number Diff line number Diff line change @@ -42,4 +42,14 @@ public function testCheckDataDecorativeFalse()
4242
4343 $ this ->assertEquals (1 , $ rule ->check (), 'Image Has Alt should have one issue. ' );
4444 }
45- }
45+
46+ public function testCheckDataDecorativeTrue ()
47+ {
48+ $ html = '<div><img src="validDecorativeImage.png" data-decorative="true" role="none"></div> ' ;
49+ $ dom = new \DOMDocument ('1.0 ' , 'utf-8 ' );
50+ $ dom ->loadHTML ($ html );
51+ $ rule = new ImageHasAlt ($ dom );
52+
53+ $ this ->assertEquals (0 , $ rule ->check (), 'Image Has Alt should have no issues. ' );
54+ }
55+ }
You can’t perform that action at this time.
0 commit comments