File tree Expand file tree Collapse file tree 3 files changed +87
-0
lines changed Expand file tree Collapse file tree 3 files changed +87
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace CidiLabs \PhpAlly \Rule ;
4
+
5
+ class IframeNotHandled extends BaseRule
6
+ {
7
+ private $ regex = array (
8
+ '@youtube\.com/embed/([^"\&\? ]+)@i ' ,
9
+ '@youtube\.com/v/([^"\&\? ]+)@i ' ,
10
+ '@youtube\.com/watch\?v=([^"\&\? ]+)@i ' ,
11
+ '@youtube\.com/\?v=([^"\&\? ]+)@i ' ,
12
+ '@youtu\.be/([^"\&\? ]+)@i ' ,
13
+ '@youtu\.be/v/([^"\&\? ]+)@i ' ,
14
+ '@youtu\.be/watch\?v=([^"\&\? ]+)@i ' ,
15
+ '@youtu\.be/\?v=([^"\&\? ]+)@i ' ,
16
+ '@youtube-nocookie\.com/embed/([^"\&\? ]+)@i ' ,
17
+ '@vimeo\.com/[^0-9]*([0-9]{7,9})@i ' ,
18
+ '/(kaltura)/ ' ,
19
+ '/(dailymotion)/ ' ,
20
+ );
21
+
22
+ public function id ()
23
+ {
24
+ return self ::class;
25
+ }
26
+
27
+ public function check ()
28
+ {
29
+ foreach ($ this ->getAllElements ('iframe ' ) as $ iframe ) {
30
+ $ matches = false ;
31
+
32
+ foreach ($ this ->regex as $ search ) {
33
+ if (preg_match ($ search , trim ($ iframe ->getAttribute ('src ' )))) {
34
+ $ matches = true ;
35
+ break ;
36
+ }
37
+ }
38
+
39
+ if (!$ matches ) {
40
+ $ this ->setIssue ($ iframe );
41
+ }
42
+ }
43
+
44
+ return count ($ this ->issues );
45
+ }
46
+ }
Original file line number Diff line number Diff line change 13
13
" CidiLabs\\ PhpAlly\\ Rule\\ FontIsNotUsed" ,
14
14
" CidiLabs\\ PhpAlly\\ Rule\\ HeadersHaveText" ,
15
15
" CidiLabs\\ PhpAlly\\ Rule\\ HeadingsInOrder" ,
16
+ " CidiLabs\\ PhpAlly\\ Rule\\ IframeNotHandled" ,
16
17
" CidiLabs\\ PhpAlly\\ Rule\\ ImageAltIsDifferent" ,
17
18
" CidiLabs\\ PhpAlly\\ Rule\\ ImageAltIsTooLong" ,
18
19
" CidiLabs\\ PhpAlly\\ Rule\\ ImageAltNotEmptyInAnchor" ,
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use CidiLabs \PhpAlly \Rule \IframeNotHandled ;
4
+
5
+ class IframeNotHandledTest extends PhpAllyTestCase {
6
+ public function testCheckEmpty ()
7
+ {
8
+ $ html = '<div></div> ' ;
9
+ $ dom = new \DOMDocument ('1.0 ' , 'utf-8 ' );
10
+ $ dom ->loadHTML ($ html );
11
+ $ rule = new IframeNotHandled ($ dom );
12
+
13
+ $ this ->assertEquals (0 , $ rule ->check (), 'IframeNotHandled should have no issues. ' );
14
+ }
15
+
16
+ public function testCheckTrueIframe ()
17
+ {
18
+ $ html = '<div><iframe src="https://www.thisisatest.com/"></iframe></div> ' ;
19
+ $ dom = new \DOMDocument ('1.0 ' , 'utf-8 ' );
20
+ $ dom ->loadHTML ($ html );
21
+ $ rule = new IframeNotHandled ($ dom );
22
+
23
+ $ this ->assertEquals (1 , $ rule ->check (), 'IframeNotHandled should have one issue. ' );
24
+ }
25
+
26
+ public function testCheckFalseIframe ()
27
+ {
28
+ $ html = '<div>
29
+ <iframe src="https://www.dailymotion.com/us"></iframe>
30
+ <iframe src="https://www.youtube.com/watch?v=1xZxxVlu7BM"></iframe>
31
+ <iframe src="https://vimeo.com/205755088"></iframe>
32
+ <iframe src="https://cdnapisec.kaltura.com/p/4183983"></iframe>
33
+ </div> ' ;
34
+ $ dom = new \DOMDocument ('1.0 ' , 'utf-8 ' );
35
+ $ dom ->loadHTML ($ html );
36
+ $ rule = new IframeNotHandled ($ dom );
37
+
38
+ $ this ->assertEquals (0 , $ rule ->check (), 'IframeNotHandled should have no issues. ' );
39
+ }
40
+ }
You can’t perform that action at this time.
0 commit comments