@@ -140,6 +140,96 @@ public function testGetFiles()
140140 $ this ->assertSame ($ expected , $ files );
141141 }
142142
143+ public function testGetFilesWithSubdirectoryNotPaths ()
144+ {
145+ // Create a subplugin directory with its own config.
146+ $ subDir = $ this ->pluginDir . '/subtype/mysub ' ;
147+ $ this ->fs ->mkdir ($ subDir . '/vendor ' );
148+ $ this ->fs ->dumpFile ($ subDir . '/lib.php ' , '<?php // Subplugin lib. ' );
149+ $ this ->fs ->dumpFile ($ subDir . '/vendor/dep.php ' , '<?php // Vendor file to exclude. ' );
150+
151+ // Subplugin config excludes 'vendor' path.
152+ $ subConfig = ['filter ' => ['notPaths ' => ['vendor ' ]]];
153+ $ this ->fs ->dumpFile ($ subDir . '/.moodle-plugin-ci.yml ' , Yaml::dump ($ subConfig ));
154+
155+ // Main plugin config excludes 'ignore' path and 'ignore_name.php' name.
156+ $ mainConfig = ['filter ' => ['notNames ' => ['ignore_name.php ' ], 'notPaths ' => ['ignore ' ]]];
157+ $ this ->fs ->dumpFile ($ this ->pluginDir . '/.moodle-plugin-ci.yml ' , Yaml::dump ($ mainConfig ));
158+
159+ $ finder = new Finder ();
160+ $ finder ->name ('*.php ' );
161+
162+ $ plugin = new MoodlePlugin ($ this ->pluginDir );
163+ $ files = $ plugin ->getFiles ($ finder );
164+
165+ // The subplugin's lib.php should be present.
166+ $ this ->assertContains (realpath ($ subDir . '/lib.php ' ), $ files );
167+
168+ // The subplugin's vendor/dep.php should be excluded by the subplugin config.
169+ $ this ->assertNotContains (realpath ($ subDir . '/vendor/dep.php ' ), $ files );
170+ }
171+
172+ public function testGetFilesWithSubdirectoryContextFilter ()
173+ {
174+ $ subDir = $ this ->pluginDir . '/subtype/mysub ' ;
175+ $ this ->fs ->mkdir ($ subDir );
176+ $ this ->fs ->dumpFile ($ subDir . '/excluded.php ' , '<?php // Should be excluded. ' );
177+ $ this ->fs ->dumpFile ($ subDir . '/included.php ' , '<?php // Should be included. ' );
178+
179+ // Context-specific filter for 'phpcs' command.
180+ $ subConfig = [
181+ 'filter ' => ['notPaths ' => ['nonexistent ' ]],
182+ 'filter-phpcs ' => ['notNames ' => ['excluded.php ' ]],
183+ ];
184+ $ this ->fs ->dumpFile ($ subDir . '/.moodle-plugin-ci.yml ' , Yaml::dump ($ subConfig ));
185+
186+ // Main plugin config excludes 'ignore' path and 'ignore_name.php' name.
187+ $ mainConfig = ['filter ' => ['notNames ' => ['ignore_name.php ' ], 'notPaths ' => ['ignore ' ]]];
188+ $ this ->fs ->dumpFile ($ this ->pluginDir . '/.moodle-plugin-ci.yml ' , Yaml::dump ($ mainConfig ));
189+
190+ $ finder = new Finder ();
191+ $ finder ->name ('*.php ' );
192+
193+ $ plugin = new MoodlePlugin ($ this ->pluginDir );
194+ $ plugin ->context = 'phpcs ' ;
195+ $ files = $ plugin ->getFiles ($ finder );
196+
197+ $ this ->assertNotContains (realpath ($ subDir . '/excluded.php ' ), $ files );
198+ $ this ->assertContains (realpath ($ subDir . '/included.php ' ), $ files );
199+ }
200+
201+ public function testGetFilesWithMultipleSubdirectoryConfigs ()
202+ {
203+ $ sub1Dir = $ this ->pluginDir . '/subtype1/sub1 ' ;
204+ $ sub2Dir = $ this ->pluginDir . '/subtype2/sub2 ' ;
205+ $ this ->fs ->mkdir ($ sub1Dir . '/generated ' );
206+ $ this ->fs ->mkdir ($ sub2Dir . '/tmp ' );
207+ $ this ->fs ->dumpFile ($ sub1Dir . '/lib.php ' , '<?php // Sub1 lib. ' );
208+ $ this ->fs ->dumpFile ($ sub1Dir . '/generated/out.php ' , '<?php // Generated. ' );
209+ $ this ->fs ->dumpFile ($ sub2Dir . '/lib.php ' , '<?php // Sub2 lib. ' );
210+ $ this ->fs ->dumpFile ($ sub2Dir . '/tmp/cache.php ' , '<?php // Cached. ' );
211+
212+ $ this ->fs ->dumpFile ($ sub1Dir . '/.moodle-plugin-ci.yml ' ,
213+ Yaml::dump (['filter ' => ['notPaths ' => ['generated ' ]]]));
214+ $ this ->fs ->dumpFile ($ sub2Dir . '/.moodle-plugin-ci.yml ' ,
215+ Yaml::dump (['filter ' => ['notPaths ' => ['tmp ' ]]]));
216+
217+ // Main plugin config excludes 'ignore' path and 'ignore_name.php' name.
218+ $ mainConfig = ['filter ' => ['notNames ' => ['ignore_name.php ' ], 'notPaths ' => ['ignore ' ]]];
219+ $ this ->fs ->dumpFile ($ this ->pluginDir . '/.moodle-plugin-ci.yml ' , Yaml::dump ($ mainConfig ));
220+
221+ $ finder = new Finder ();
222+ $ finder ->name ('*.php ' );
223+
224+ $ plugin = new MoodlePlugin ($ this ->pluginDir );
225+ $ files = $ plugin ->getFiles ($ finder );
226+
227+ $ this ->assertNotContains (realpath ($ sub1Dir . '/generated/out.php ' ), $ files );
228+ $ this ->assertNotContains (realpath ($ sub2Dir . '/tmp/cache.php ' ), $ files );
229+ $ this ->assertContains (realpath ($ sub1Dir . '/lib.php ' ), $ files );
230+ $ this ->assertContains (realpath ($ sub2Dir . '/lib.php ' ), $ files );
231+ }
232+
143233 public function testGetRelativeFiles ()
144234 {
145235 // Ignore some files for better testing.
0 commit comments