diff --git a/include/class.export.php b/include/class.export.php index 6a25afc4fe760931e1b41f72689cd0063c45e883..3a47bcc942e358d51fa6615bbd9d065a887182ba 100644 --- a/include/class.export.php +++ b/include/class.export.php @@ -390,7 +390,7 @@ class ResultSetExporter { function dump() { # Useful for debug output while ($row=$this->nextArray()) { - var_dump($row); + var_dump($row); //nolint } } } diff --git a/include/class.pdf.php b/include/class.pdf.php index c12d071e82dd48058513fad2d1a89dcf5efb25a7..cc395f388999d1230b0da195747e9a9990ee22df 100644 --- a/include/class.pdf.php +++ b/include/class.pdf.php @@ -45,6 +45,10 @@ class mPDFWithLocalImages extends mPDF { ); return call_user_func_array(array('parent', 'WriteHtml'), $args); } + + function output($name, $dest) { + return parent::Output($name, $dest); + } } class Ticket2PDF extends mPDFWithLocalImages diff --git a/include/class.task.php b/include/class.task.php index 1456272458d49d78463916f6c85f04ff00cc74cd..367fa60623735a87058dce350415c0add755e728 100644 --- a/include/class.task.php +++ b/include/class.task.php @@ -995,7 +995,7 @@ class Task extends TaskModel implements RestrictedAccess, Threadable { $pdf = new Task2PDF($this, $options); $name = 'Task-'.$this->getNumber().'.pdf'; - Http::download($name, 'application/pdf', $pdf->Output($name, 'S')); + Http::download($name, 'application/pdf', $pdf->output($name, 'S')); //Remember what the user selected - for autoselect on the next print. $_SESSION['PAPER_SIZE'] = $options['psize']; exit; diff --git a/include/class.ticket.php b/include/class.ticket.php index cbfa765800763b6e6c6ea8a7c5a0d9633e4dcc0c..3d7e148ca7040e29302d943d5fb3308dddc89c88 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -3089,7 +3089,7 @@ implements RestrictedAccess, Threadable, Searchable { $pdf = new Ticket2PDF($this, $psize, $notes); $name = 'Ticket-'.$this->getNumber().'.pdf'; - Http::download($name, 'application/pdf', $pdf->Output($name, 'S')); + Http::download($name, 'application/pdf', $pdf->output($name, 'S')); //Remember what the user selected - for autoselect on the next print. $_SESSION['PAPER_SIZE'] = $psize; exit; diff --git a/setup/test/run-tests.php b/setup/test/run-tests.php index fe55e681e06a947511848e8d3a9a669e339485bb..9834aa90a684456a246cc7dc9fa3d07e892cbc2c 100644 --- a/setup/test/run-tests.php +++ b/setup/test/run-tests.php @@ -43,7 +43,7 @@ if (function_exists('pcntl_signal')) { foreach (glob_recursive(dirname(__file__)."/tests/test.*.php") as $t) { if (strpos($t,"class.") !== false) continue; - $class = (include $t); + $class = @(include $t); if (!is_string($class)) continue; if($selected_test && ($class != $selected_test)) diff --git a/setup/test/tests/class.test.php b/setup/test/tests/class.test.php index 5dd6097dcb127a1a3391d36361872ed0e6b5dec2..db05c2c16a88c069b55ddace79e641430d5398cd 100644 --- a/setup/test/tests/class.test.php +++ b/setup/test/tests/class.test.php @@ -31,10 +31,15 @@ class Test { function teardown() { } - static function getAllScripts($excludes=true, $root=false) { + function ignore3rdparty() { + return true; + } + + function getAllScripts($pattern='*.php', $root=false, $excludes=true) { $root = $root ?: get_osticket_root_path(); + $excludes = $excludes ?: $this->ignore3rdparty(); $scripts = array(); - foreach (glob_recursive("$root/*.php") as $s) { + foreach (glob_recursive("$root/$pattern") as $s) { $found = false; if ($excludes) { foreach (self::$third_party_paths as $p) { @@ -88,20 +93,20 @@ class Test { foreach ($rc->getMethods() as $m) { if (stripos($m->name, 'test') === 0) { $this->setup(); - call_user_func(array($this, $m->name)); + @call_user_func(array($this, $m->name)); $this->teardown(); } } } - function line_number_for_offset($filename, $offset) { - $lines = file($filename); - $bytes = $line = 0; - while ($bytes < $offset) { - $bytes += strlen(array_shift($lines)); - $line += 1; - } - return $line; + function line_number_for_offset($file, $offset) { + + if (is_file($file)) + $content = file_get_contents($file, false, null, 0, $offset); + else + $content = @substr($file, 0, $offset); + + return count(explode("\n", $content)); } } diff --git a/setup/test/tests/stubs.php b/setup/test/tests/stubs.php index 0ad23392642a6e1d4cedd18e7876e44fd1972d35..6a7b0d285ea0e9898f600365ca692f29c768f1c0 100644 --- a/setup/test/tests/stubs.php +++ b/setup/test/tests/stubs.php @@ -104,6 +104,7 @@ class Phar { function startBuffering() {} function stopBuffering() {} function setSignatureAlgorithm() {} + function compress() {} } class ZipArchive { @@ -114,6 +115,10 @@ class ZipArchive { function setExternalAttributesName() {} } +class Spyc { + function YAMLLoad() {} +} + class finfo { function file() {} function buffer() {} @@ -176,6 +181,7 @@ class NumberFormatter { class Collator { function setStrength() {} + function compare() {} } class Aws_Route53_Client { @@ -189,4 +195,43 @@ class Memcache { function set() {} function get() {} } + +class Crypt_Hash { + function setKey() {} + function setIV() {} +} + +class Crypt_AES { + function setKey() {} + function setIV() {} + function enableContinuousBuffer() {} +} + +class PEAR { + function isError() {} + function mail() {} +} + +class mail { + function factory() {} + function connect() {} + function disconnect() {} +} + +class Mail_mime { + function headers() {} + function setTXTBody() {} + function setHTMLBody() {} + function addCc() {} +} + +class mPDF { + function Output() {} +} + +class HashPassword { + function CheckPassword() {} + function HashPassword() {} +} + ?> diff --git a/setup/test/tests/test.extra-whitespace.php b/setup/test/tests/test.extra-whitespace.php index 96d31ac8425e40a38e66ff90f7a59e9717697bb9..ff3fc7be0721cd981de6550ba051a540565c6b28 100644 --- a/setup/test/tests/test.extra-whitespace.php +++ b/setup/test/tests/test.extra-whitespace.php @@ -3,16 +3,17 @@ require_once "class.test.php"; class ExtraWhitespace extends Test { var $name = "PHP Leading and Trailing Whitespace"; - + function testFindWhitespace() { foreach ($this->getAllScripts() as $s) { $matches = array(); + $content = file_get_contents($s); if (preg_match_all('/^\s+<\?php|\?>\n\s+$/s', - file_get_contents($s), $matches, + $content, $matches, PREG_OFFSET_CAPTURE) > 0) { foreach ($matches[0] as $match) $this->fail( - $s, $this->line_number_for_offset($s, $match[1]), + $s, $this->line_number_for_offset($content, $match[1]), (strpos('?>', $match[0]) !== false) ? 'Leading whitespace' : 'Trailing whitespace'); diff --git a/setup/test/tests/test.jslint.php b/setup/test/tests/test.jslint.php index 5f8fcfca9378b8eef6441e0f71e5d7853dcb28dc..e916715c663587d14f20be9dc213011c00055d1a 100644 --- a/setup/test/tests/test.jslint.php +++ b/setup/test/tests/test.jslint.php @@ -6,8 +6,7 @@ class JsSyntaxTest extends Test { function testLintErrors() { $exit = 0; - $root = get_osticket_root_path(); - foreach (glob_recursive("$root/*.js") as $s) { + foreach ($this->getAllScripts('*.js') as $s) { ob_start(); system("jsl -process $s", $exit); $line = ob_get_contents(); diff --git a/setup/test/tests/test.shortopentags.php b/setup/test/tests/test.shortopentags.php index 571fc08e15e1c3af5c0c60216eeda7d494a6cfa6..ec5b8669e454c6ae735aeb81fbfaba94f0f4e016 100644 --- a/setup/test/tests/test.shortopentags.php +++ b/setup/test/tests/test.shortopentags.php @@ -7,13 +7,14 @@ class ShortOpenTag extends Test { function testFindShortOpens() { foreach ($this->getAllScripts() as $s) { $matches = array(); + $content = file_get_contents($s); if (preg_match_all('/<\?\s*(?!php|xml).*$/m', - file_get_contents($s), $matches, + $content, $matches, PREG_OFFSET_CAPTURE) > 0) { foreach ($matches[0] as $match) $this->fail( $s, - $this->line_number_for_offset($s, $match[1]), + $this->line_number_for_offset($content, $match[1]), $match[0]); } else $this->pass(); diff --git a/setup/test/tests/test.signals.php b/setup/test/tests/test.signals.php index 7ce888383ab0aee781450f3f908d8c4a36d96ae1..0f6287a0a9e0a8414d39cecacdf2a2ed99704964 100644 --- a/setup/test/tests/test.signals.php +++ b/setup/test/tests/test.signals.php @@ -16,14 +16,15 @@ class SignalsTest extends Test { foreach ($matches as $match) $published_signals[] = $match[1]; foreach ($scripts as $s) { + $content = file_get_contents($s); if (preg_match_all("/^ *Signal::connect\('([^']+)'/m", - file_get_contents($s), $matches, + $content, $matches, PREG_OFFSET_CAPTURE|PREG_SET_ORDER) > 0) { foreach ($matches as $match) { $match = $match[1]; if (!in_array($match[0], $published_signals)) $this->fail( - $s, self::line_number_for_offset($s, $match[1]), + $s, $this->line_number_for_offset($content, $match[1]), "Signal '{$match[0]}' is never sent"); else $this->pass(); @@ -31,16 +32,6 @@ class SignalsTest extends Test { } } } - - function line_number_for_offset($filename, $offset) { - $lines = file($filename); - $bytes = $line = 0; - while ($bytes < $offset) { - $bytes += strlen(array_shift($lines)); - $line += 1; - } - return $line; - } } return 'SignalsTest'; diff --git a/setup/test/tests/test.syntax.php b/setup/test/tests/test.syntax.php index 0adf1465a3fcca066262efe308222e8da1e48720..cc528f52fb53b8174caf96a61652c11f29bde818 100644 --- a/setup/test/tests/test.syntax.php +++ b/setup/test/tests/test.syntax.php @@ -4,9 +4,13 @@ require_once "class.test.php"; class SyntaxTest extends Test { var $name = "PHP Syntax Checks"; + function ignore3rdparty() { + return false; + } + function testCompileErrors() { $exit = 0; - foreach ($this->getAllScripts(false) as $s) { + foreach ($this->getAllScripts() as $s) { ob_start(); system("php -l $s", $exit); $line = ob_get_contents(); diff --git a/setup/test/tests/test.undefinedmethods.php b/setup/test/tests/test.undefinedmethods.php index 83a227eeeae0da98b146908f50055c2b2387ff97..16f4e76e1678ac5e755e4c23235a5279e348cb03 100644 --- a/setup/test/tests/test.undefinedmethods.php +++ b/setup/test/tests/test.undefinedmethods.php @@ -4,8 +4,12 @@ require_once "class.test.php"; class UndefinedMethods extends Test { var $name = "Access to undefined object methods"; - function testFindShortOpen() { - $scripts = $this->getAllScripts(false); + function ignore3rdparty() { + return false; + } + + function testUndefinedMethods() { + $scripts = $this->getAllScripts(); $function_defs = array(); foreach ($scripts as $s) { $matches = array(); diff --git a/setup/test/tests/test.var-dump.php b/setup/test/tests/test.var-dump.php new file mode 100644 index 0000000000000000000000000000000000000000..1244ec7b5e1c1e95e037946d105ae70cf8a92fdf --- /dev/null +++ b/setup/test/tests/test.var-dump.php @@ -0,0 +1,27 @@ +<?php +require_once "class.test.php"; + +class VarDump extends Test { + var $name = "var_dump Checks"; + + function testFindShortOpens() { + $re = '/^(([\t ]*?)var_dump\(.*[\)|,|;])((?!nolint).)*$/m'; + foreach ($this->getAllScripts() as $s) { + $matches = array(); + $content = file_get_contents($s); + if (preg_match_all($re, + $content, $matches, + PREG_OFFSET_CAPTURE) > 0) { + foreach ($matches[0] as $match) { + $this->fail( + $s, + $this->line_number_for_offset($content, $match[1]), + trim($match[0])); + } + } + else $this->pass(); + } + } +} +return 'VarDump'; +?>