Skip to content

Commit

Permalink
mostly stuff regarding bug 62539
Browse files Browse the repository at this point in the history
  • Loading branch information
paul999 committed Dec 22, 2010
1 parent 9273958 commit d5826a3
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 20 deletions.
1 change: 1 addition & 0 deletions cli.php
Expand Up @@ -44,6 +44,7 @@

$mpv = new mpv(null, mpv::UNZIP_PREFERENCE, false);
$mpv->output_type = (mpv::OUTPUT_TEXT);
mpv::$exec_php = mpv::EXEC_PHP;
$mpv->validate($argv[1]);

print $lang['VALIDATION_RESULTS'] . "\n\n" . $mpv;
47 changes: 43 additions & 4 deletions includes/mpv.php
Expand Up @@ -122,6 +122,14 @@ class mpv
*/
private $message;

/**
* Array of "unwanted files/directories", all strtolowered
*
* @access private
* @var array
*/
public static $unwanted_files;

/**
* Output type; either OUTPUT_BBCODE or OUTPUT_HTML
*
Expand Down Expand Up @@ -161,6 +169,15 @@ class mpv
* @var array
*/
public $package_files;


/**
* Array containing all directories in a MOD package
*
* @access public
* @var array
*/
public static $package_directories = array();

/**
* Array containing all XSL files
Expand Down Expand Up @@ -316,6 +333,11 @@ public function __construct($dir = null, $unzip_type = self::UNZIP_PREFERENCE, $
unset($exec_check);
}

if (defined('UNWANTED') && UNWANTED)
{
self::$unwanted_files = explode('|', UNWANTED);
}

$this->unzip_type = $unzip_type;
$this->remove_zip = $remove_zip;
$this->exec_php = self::DONT_EXEC_PHP;
Expand All @@ -325,10 +347,11 @@ public function __construct($dir = null, $unzip_type = self::UNZIP_PREFERENCE, $
$this->errors = array();
$this->message = '';

$this->xsl_files = array();
$this->modx_files = array();
$this->package_files = array();
$this->test_collections = array();
$this->xsl_files = array();
$this->modx_files = array();
$this->package_files = array();
$this->package_directories = array();
$this->test_collections = array();

$this->output_type = self::OUTPUT_BBCODE;

Expand All @@ -354,6 +377,20 @@ public function __construct($dir = null, $unzip_type = self::UNZIP_PREFERENCE, $
}
}

/**
* Check if the file is unwanted or not.
*
* @param string $directory
* @return boolean
*/
public static function check_unwanted($directory)
{
$regexp = '#(^|.*/)(' . implode('|', array_map('preg_quote', self::$unwanted_files)) . ')(?:/|$)#i';

return preg_match($regexp, $directory) ? true : false;
}


/**
* error handler
*
Expand Down Expand Up @@ -740,6 +777,8 @@ public static function dir_files($root, $dir = '')
{
$dir .= '/';
}

self::$package_directories[] = $dir;

if ($dh = opendir($root . $dir))
{
Expand Down
5 changes: 5 additions & 0 deletions includes/tests/tests_code.php
Expand Up @@ -97,6 +97,11 @@ public function run()
foreach ($this->validator->package_files as $package_file)
{
$this->file_name = $package_file;

if (mpv::check_unwanted($package_file))
{
continue;
}

// Only test PHP files
// We also check files that should be binary, but arent.
Expand Down
5 changes: 5 additions & 0 deletions includes/tests/tests_execution.php
Expand Up @@ -110,6 +110,11 @@ public function run()

foreach ($this->validator->package_files as $package_file)
{
if (mpv::check_unwanted($package_file))
{
continue;
}

$this->file_name = $package_file;

// Only test PHP files
Expand Down
7 changes: 6 additions & 1 deletion includes/tests/tests_html.php
Expand Up @@ -103,6 +103,11 @@ public function run()

foreach ($files as $package_file)
{
if (mpv::check_unwanted($package_file))
{
continue;
}

// Only test html, php, xml files
if (!in_array(strrchr($package_file, '.'), array('.php', '.xml', '.html')))
{
Expand Down Expand Up @@ -316,4 +321,4 @@ public function return_failed_tests()
{
return $this->failed_tests;
}
}
}
5 changes: 5 additions & 0 deletions includes/tests/tests_lang.php
Expand Up @@ -109,6 +109,11 @@ public function run()
{
continue;
}*/

if (mpv::check_unwanted($package_file))
{
continue;
}

$this->failed_tests = array();

Expand Down
5 changes: 5 additions & 0 deletions includes/tests/tests_modx.php
Expand Up @@ -99,6 +99,11 @@ public function run()
foreach ($this->validator->modx_files as $modx_filename => $modx_object)
{
$this->modx_filename = $modx_filename;

if (mpv::check_unwanted($modx_filename))
{
continue;
}

if (preg_match('#modx-(.*?)\.xsd#s', (string) $modx_object, $matches))
{
Expand Down
28 changes: 13 additions & 15 deletions includes/tests/tests_packaging.php
Expand Up @@ -41,15 +41,6 @@ class mpv_tests_packaging
* @var array
*/
private $failed_tests;

/**
* Array of "unwanted files", all strtolowered
*
* @access private
* @var array
*/
private $unwanted_files = array('__macosx', '.ds_store', 'thumbs.db', '.svn');


/**
* String with valid MD5 for license.txt
Expand Down Expand Up @@ -229,6 +220,11 @@ private function test_license()
{
foreach ($this->validator->package_files as $filename)
{
if (mpv::check_unwanted($filename))
{
continue;
}

if (strtolower(basename($filename)) == 'license.txt')
{
return true;
Expand All @@ -249,6 +245,11 @@ private function test_prosilver_english()
$return = true;
foreach ($this->validator->package_files as $filename)
{
if (mpv::check_unwanted($filename))
{
continue;
}

$file = strtolower(basename($filename));

if ($file == 'prosilver.xml' || (strpos($file, 'prosilver') !== false && strpos($file, '.xml') !== false))
Expand All @@ -275,14 +276,11 @@ private function test_prosilver_english()
*/
private function test_unwanted()
{
/**
* @TODO: Does this work? I never saw a notice regarding it?
*/
// precache regexp for efficiency
$regexp = '#(^|.*/)(' . implode('|', array_map('preg_quote', $this->unwanted_files)) . ')(?:/|$)#i';
$regexp = '#(^|.*/)(' . implode('|', array_map('preg_quote', mpv::$unwanted_files)) . ')(?:/|$)#i';

$unwanted_files = array();
foreach ($this->validator->package_files as $filename)
foreach (mpv::$package_directories as $filename)
{
if (preg_match($regexp, $filename, $matches))
{
Expand All @@ -302,7 +300,7 @@ private function test_unwanted()
}

// push notice
$this->push_error(mpv::ERROR_NOTICE, 'UNWANTED_FILE', null, array($matches[1], $matches[2]));
$this->push_error(mpv::ERROR_FAIL, 'UNWANTED_FILE', null, array($matches[1], $matches[2]));
}
}

Expand Down
4 changes: 4 additions & 0 deletions mpv_config.php
Expand Up @@ -44,6 +44,10 @@
// Use the _exact_ directory name
define('MPV_LANG', 'en');

// Files that generate a warning, and that _arent_ checked.
// Seperate with |
define('UNWANTED', '__macosx|.ds_store|thumbs.db|.svn|.git|.project');

// This is for statistics gathering
// Format is: 'tag' => array('properties')
$statistics = array(
Expand Down
1 change: 1 addition & 0 deletions store/temp/mpv_79018bc398526d94c8c9f54d14a7c172
Submodule mpv_79018bc398526d94c8c9f54d14a7c172 added at a976d5
1 change: 1 addition & 0 deletions store/temp/mpv_a7e94281214d68f87f35650c7c530d99
Submodule mpv_a7e94281214d68f87f35650c7c530d99 added at a976d5
Binary file modified test-file.zip
Binary file not shown.

2 comments on commit d5826a3

@jellydoughnut
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to git ignore the store directory :)

@paul999
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed yeah :)

Please sign in to comment.