File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
src/PatternLab/PatternEngine/Twig Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -211,4 +211,46 @@ public static function loadTags($instance) {
211211 return $ instance ;
212212
213213 }
214+
215+ /**
216+ * Load functions for the Twig PatternEngine
217+ * @param {Instance} an instance of the twig engine
218+ *
219+ * @return {Instance} an instance of the twig engine
220+ */
221+ public static function loadTests ($ instance ) {
222+
223+ // load defaults
224+ $ testDir = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_twig-components/tests " ;
225+ $ testExt = Config::getOption ("twigTestExt " );
226+ $ testExt = $ testExt ? $ testExt : "test.twig " ;
227+
228+ if (is_dir ($ testDir )) {
229+
230+ // loop through the test dir...
231+ $ finder = new Finder ();
232+ $ finder ->files ()->name ("*\. " .$ testExt )->in ($ testDir );
233+ $ finder ->sortByName ();
234+ foreach ($ finder as $ file ) {
235+
236+ include ($ file ->getPathname ());
237+
238+ // $test should be defined in the included file
239+ if (isset ($ test )) {
240+ $ instance ->addTest ($ test );
241+ unset($ test );
242+ }
243+
244+ }
245+
246+ } else {
247+
248+ self ::dirNotExist ($ testDir );
249+
250+ }
251+
252+ return $ instance ;
253+
254+ }
255+
214256}
You can’t perform that action at this time.
0 commit comments