@@ -32,6 +32,45 @@ public static function setUpBeforeClass() : void
32
32
self ::$ validator = new \HtmlValidator \Validator ($ url );
33
33
}
34
34
35
+ /**
36
+ * Validate all files in a directory.
37
+ *
38
+ * @param string $type one of 'Valid' (html), 'NotWarning' (html), 'ValidCSS', or 'NotWarningCSS'
39
+ * @param array<string> $extensions
40
+ */
41
+ public function assertDirectory (string $ type , string $ directory , string $ message = '' , bool $ recurseSubdirectories = true , array $ extensions = ['.css ' ]) : void
42
+ {
43
+ $ this ->assertContains ($ type , ['Valid ' , 'NotWarning ' , 'ValidCSS ' , 'NotWarningCSS ' ], 'Invalid parameter for ' . __METHOD__ );
44
+ $ method = "assert {$ type }File " ;
45
+
46
+ if ($ recurseSubdirectories )
47
+ {
48
+ $ iterator = new \RecursiveIteratorIterator (
49
+ new \RecursiveDirectoryIterator ($ directory , \RecursiveDirectoryIterator::SKIP_DOTS ),
50
+ \RecursiveIteratorIterator::SELF_FIRST
51
+ );
52
+ }
53
+ else
54
+ {
55
+ $ iterator = new \DirectoryIterator ($ directory );
56
+ }
57
+ $ exts = \array_flip ($ extensions );
58
+
59
+ foreach ($ iterator as $ item )
60
+ {
61
+ if ('file ' == $ item ->getType ())
62
+ {
63
+ $ file = $ item ->getPathname ();
64
+ $ ext = \strrchr ($ file , '. ' );
65
+
66
+ if ($ ext && isset ($ exts [$ ext ]))
67
+ {
68
+ $ this ->{$ method }($ file , $ message . ' File: ' . $ file );
69
+ }
70
+ }
71
+ }
72
+ }
73
+
35
74
public function assertNotWarningCss (string $ css , string $ message = '' ) : void
36
75
{
37
76
$ response = $ this ->validateCss ($ css );
@@ -80,45 +119,6 @@ public function assertValidCss(string $css, string $message = '') : void
80
119
self ::assertThat ($ response , new ErrorConstraint (), $ message );
81
120
}
82
121
83
- /**
84
- * Validate all files in a directory.
85
- *
86
- * @param string $type one of 'Valid' (html), 'NotWarning' (html), 'ValidCSS', or 'NotWarningCSS'
87
- * @param array<string> $extensions
88
- */
89
- public function assertDirectory (string $ type , string $ directory , string $ message = '' , bool $ recurseSubdirectories = true , array $ extensions = ['.css ' ]) : void
90
- {
91
- $ this ->assertContains ($ type , ['Valid ' , 'NotWarning ' , 'ValidCSS ' , 'NotWarningCSS ' ], 'Invalid parameter for ' . __METHOD__ );
92
- $ method = "assert {$ type }File " ;
93
-
94
- if ($ recurseSubdirectories )
95
- {
96
- $ iterator = new \RecursiveIteratorIterator (
97
- new \RecursiveDirectoryIterator ($ directory , \RecursiveDirectoryIterator::SKIP_DOTS ),
98
- \RecursiveIteratorIterator::SELF_FIRST
99
- );
100
- }
101
- else
102
- {
103
- $ iterator = new \DirectoryIterator ($ directory );
104
- }
105
- $ exts = \array_flip ($ extensions );
106
-
107
- foreach ($ iterator as $ item )
108
- {
109
- if ('file ' == $ item ->getType ())
110
- {
111
- $ file = $ item ->getPathname ();
112
- $ ext = \strrchr ($ file , '. ' );
113
-
114
- if ($ ext && isset ($ exts [$ ext ]))
115
- {
116
- $ this ->{$ method }($ file , $ message . ' File: ' . $ file );
117
- }
118
- }
119
- }
120
- }
121
-
122
122
public function assertValidCssFile (string $ file , string $ message = '' ) : void
123
123
{
124
124
$ response = $ this ->validateCss ($ this ->getFromFile ($ file ));
0 commit comments