diff options
Diffstat (limited to 'modules/gallery/tests/File_Structure_Test.php')
-rw-r--r-- | modules/gallery/tests/File_Structure_Test.php | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/modules/gallery/tests/File_Structure_Test.php b/modules/gallery/tests/File_Structure_Test.php index c517bd72..8a97e00b 100644 --- a/modules/gallery/tests/File_Structure_Test.php +++ b/modules/gallery/tests/File_Structure_Test.php @@ -84,6 +84,7 @@ class File_Structure_Test extends Unit_Test_Case { $expected = array("<?php defined('SYSPATH') OR die('No direct access allowed.');\n"); } else if (strpos($path, MODPATH . "forge") === 0 || strpos($path, MODPATH . "exif/lib") === 0 || + strpos($path, MODPATH . "gallery/lib/HTMLPurifier") === 0 || $path == MODPATH . "user/lib/PasswordHash.php" || $path == DOCROOT . "var/database.php") { // 3rd party module security-only preambles, similar to Gallery's @@ -136,7 +137,7 @@ class File_Structure_Test extends Unit_Test_Case { public function code_files_start_with_preamble_test() { $dir = new PhpCodeFilterIterator( - new RecursiveIteratorIterator(new RecursiveDirectoryIterator(DOCROOT))); + new RecursiveIteratorIterator(new RecursiveDirectoryIterator(DOCROOT))); $errors = array(); foreach ($dir as $file) { @@ -212,6 +213,43 @@ class File_Structure_Test extends Unit_Test_Case { } } } + + public function module_info_is_well_formed_test() { + $info_files = array_merge( + glob("modules/*/module.info"), + glob("themes/*/module.info")); + + $errors = array(); + foreach ($info_files as $file) { + foreach (file($file) as $line) { + $parts = explode("=", $line, 2); + $values[trim($parts[0])] = trim($parts[1]); + } + + $module = dirname($file); + // Certain keys must exist + foreach (array("name", "description", "version") as $key) { + if (!array_key_exists($key, $values)) { + $errors[] = "$module: missing key $key"; + } + } + + // Any values containing spaces must be quoted + foreach ($values as $key => $value) { + if (strpos($value, " ") !== false && !preg_match('/^".*"$/', $value)) { + $errors[] = "$module: value for $key must be quoted"; + } + } + + // The file must parse + if (!is_array(parse_ini_file($file))) { + $errors[] = "$module: info file is not parseable"; + } + } + if ($errors) { + $this->assert_true(false, $errors); + } + } } class PhpCodeFilterIterator extends FilterIterator { @@ -239,6 +277,7 @@ class GalleryCodeFilterIterator extends FilterIterator { strpos($path_name, MODPATH . "user/lib/PasswordHash") !== false || strpos($path_name, DOCROOT . "lib/swfupload") !== false || strpos($path_name, SYSPATH) !== false || + strpos($path_name, MODPATH . "gallery/libraries/HTMLPurifier") !== false || substr($path_name, -1, 1) == "~"); } } |