Yeah, it's not test code, it's a real hook: https://www.mediawiki.org/wiki/Manual:Hooks/TestCanonicalRedirect
In general I would recommend against deleting random files from the source code ;) , it's likely to cause errors. You might instead want to disallow the web server from reading the test files, using .htaccess rules or something.
If you want to keep your current (scary) approach, then try changing your 'find' command to only find directories, by adding '-type d' to the arguments.