From b3e175006cc3be2c1793797e726095520ba16d9c Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 23 Oct 2009 07:48:07 -0700 Subject: Move the filters that the File_Structure_Test use into a seperate file so other tests. can use them. Add a No_Direct_ORM_Access_Test to find all places that the user or group table are accessed outside of the user module. This test will fail at this point, as it in preparation for the IdentityProvider refactor. --- modules/user/tests/No_Direct_ORM_Access_Test.php | 77 ++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 modules/user/tests/No_Direct_ORM_Access_Test.php (limited to 'modules/user/tests') diff --git a/modules/user/tests/No_Direct_ORM_Access_Test.php b/modules/user/tests/No_Direct_ORM_Access_Test.php new file mode 100644 index 00000000..440321fa --- /dev/null +++ b/modules/user/tests/No_Direct_ORM_Access_Test.php @@ -0,0 +1,77 @@ + $line) { + if (preg_match('/ORM::factory\\(\"user\"/', $line)) { + $errors[] = "$file($l) => $line"; + } + } + } + $file_as_string = null; + } + if ($errors) { + $this->assert_false(true, "Direct access to the users table found:\n" . join("\n", $errors)); + } + } + + public function no_access_to_groups_table_test() { + $dir = new UserModuleFilterIterator( + new PhpCodeFilterIterator( + new GalleryCodeFilterIterator( + new RecursiveIteratorIterator( + new RecursiveDirectoryIterator(DOCROOT))))); + $errors = array(); + foreach ($dir as $file) { + $file_as_string = file_get_contents($file); + if (preg_match("/ORM::factory\\(\"group\"/", $file_as_string)) { + foreach (split("\n", $file_as_string) as $l => $line) { + if (preg_match('/ORM::factory\\(\"group\"/', $line)) { + $errors[] = "$file($l) => $line"; + } + } + } + $file_as_string = null; + } + if ($errors) { + $this->assert_false(true, "Direct access to the groups table found:\n" . join("\n", $errors)); + } + } + +} + +class UserModuleFilterIterator extends FilterIterator { + public function accept() { + $path_name = $this->getInnerIterator()->getPathName(); + return strpos($path_name, "/modules/user") === false; + } +} -- cgit v1.2.3