Permalink
Browse files

Reverted a change from this afternoon to fix includes.

Added a phpunits for first parts, rest follow soon hopefully.

Fixed a few bugs I found while writing the tests.
  • Loading branch information...
1 parent aadea7a commit 632454716d31ca444b1c8964c86ce716ec884173 @paul999 paul999 committed Jun 18, 2011
Showing with 841 additions and 6 deletions.
  1. +9 −2 includes/tests/test_base.php
  2. +6 −4 includes/tests/tests_code.php
  3. +25 −0 phpunit.xml.all
  4. +31 −0 phpunit.xml.dist
  5. +13 −0 tests/bootstrap.php
  6. +50 −0 tests/code/binary_test.php
  7. +59 −0 tests/code/db_test.php
  8. +49 −0 tests/code/empty_test.php
  9. +68 −0 tests/code/function_test.php
  10. +58 −0 tests/code/in_phpbb_test.php
  11. +64 −0 tests/code/include_test.php
  12. +51 −0 tests/code/request_var_test.php
  13. +52 −0 tests/code/short_test.php
  14. +1 −0 tests/code/testcode/dbal/db2
  15. +1 −0 tests/code/testcode/dbal/ibase
  16. +1 −0 tests/code/testcode/dbal/mssql
  17. +1 −0 tests/code/testcode/dbal/mysql
  18. +1 −0 tests/code/testcode/dbal/mysqli
  19. +1 −0 tests/code/testcode/dbal/oci
  20. +1 −0 tests/code/testcode/dbal/odbc
  21. +1 −0 tests/code/testcode/dbal/pg
  22. +1 −0 tests/code/testcode/dbal/sqlite
  23. +1 −0 tests/code/testcode/dbal/sqlsrv
  24. 0 tests/code/testcode/emptyFile
  25. +1 −0 tests/code/testcode/functions/addslashes
  26. +1 −0 tests/code/testcode/functions/backticks
  27. +1 −0 tests/code/testcode/functions/die
  28. +1 −0 tests/code/testcode/functions/eval
  29. +1 −0 tests/code/testcode/functions/exec
  30. +1 −0 tests/code/testcode/functions/getenv
  31. +1 −0 tests/code/testcode/functions/include_once
  32. +1 −0 tests/code/testcode/functions/include_once2
  33. +1 −0 tests/code/testcode/functions/md5
  34. +8 −0 tests/code/testcode/functions/md52
  35. +1 −0 tests/code/testcode/functions/passthru
  36. +1 −0 tests/code/testcode/functions/require_once
  37. +1 −0 tests/code/testcode/functions/require_once2
  38. +1 −0 tests/code/testcode/functions/sha1
  39. +1 −0 tests/code/testcode/functions/stripslashes
  40. +1 −0 tests/code/testcode/functions/system
  41. +3 −0 tests/code/testcode/include/include1
  42. +3 −0 tests/code/testcode/include/include2
  43. +3 −0 tests/code/testcode/include/include3
  44. +6 −0 tests/code/testcode/include/include4
  45. +6 −0 tests/code/testcode/include/include5
  46. +3 −0 tests/code/testcode/include/include6
  47. +3 −0 tests/code/testcode/include/include7
  48. +3 −0 tests/code/testcode/include/includeonce1
  49. +3 −0 tests/code/testcode/include/includeonce2
  50. +3 −0 tests/code/testcode/include/require1
  51. +3 −0 tests/code/testcode/include/require2
  52. +3 −0 tests/code/testcode/include/requireonce1
  53. +3 −0 tests/code/testcode/include/requireonce2
  54. +3 −0 tests/code/testcode/inphpbb.php
  55. +3 −0 tests/code/testcode/inphpbb3.php
  56. +1 −0 tests/code/testcode/noBinary
  57. +2 −0 tests/code/testcode/noExtension
  58. +3 −0 tests/code/testcode/noShort
  59. +3 −0 tests/code/testcode/noinphpbb.php
  60. +6 −0 tests/code/testcode/phpbb.php
  61. +5 −0 tests/code/testcode/requestVar1
  62. +5 −0 tests/code/testcode/requestVar2
  63. +5 −0 tests/code/testcode/requestVar3
  64. +2 −0 tests/code/testcode/short1
  65. +2 −0 tests/code/testcode/short2
  66. +2 −0 tests/code/testcode/short3
  67. +3 −0 tests/code/testcode/short4
  68. +5 −0 tests/code/testcode/unixFile
  69. +5 −0 tests/code/testcode/windowsFile
  70. +49 −0 tests/code/unix_test.php
  71. +37 −0 tests/test_framework/mpv_mock.php
  72. +43 −0 tests/test_framework/phpbb_test_case.php
  73. +44 −0 tests/test_framework/phpbb_test_case_helpers.php
@@ -248,7 +248,14 @@ protected function extract_dir($file)
**/
public function unittest($function, $parameters)
{
- call_user_func_array(array($this, $function), $parameters);
- }
+ return call_user_func_array(array($this, $function), $parameters);
+ }
+
+ public function setFilename($file)
+ {
+ $this->file_name = $file;
+ $this->file_contents = @file_get_contents($file);
+ $this->file_contents_file = @file($file);
+ }
}
?>
@@ -238,7 +238,7 @@ protected function test_dbal()
$functions = array(
'mysql_',
- 'mysqli_',
+ 'mysqli_',
'oci_',
'sqlite_',
'pg_',
@@ -251,6 +251,7 @@ protected function test_dbal()
foreach ($functions as $function)
{
+
if (preg_match("#(^\s*|[^a-z0-9_])" . preg_quote($function, '#') . "{1}([a-zA-Z0-9_]+){1,}\s*\({1}#si", $this->file_contents))
{
$return = $this->display_line_code(mpv::ERROR_FAIL, 'USAGE_' . strtoupper(str_replace(array('_', '$', '('), '', $function)), false, "#(^\s*|[^a-z0-9_])" . preg_quote($function, '#') . "{1}([a-zA-Z0-9_]+){1,}\s*\({1}#si", array('new', 'function'));
@@ -272,7 +273,7 @@ protected function test_code()
$functions = array(
'eval',
'exec',
- 'sytem',
+ 'system',
'passthru',
'getenv',
'die',
@@ -312,7 +313,7 @@ protected function test_code()
foreach ($functions_notice as $function)
{
- if (preg_match("#(^\s*|[^a-z0-9_])" . preg_quote($function, '#') . "{1}\s*\({1}#si", $this->file_contents))
+ if (preg_match("#(^\s*|[^a-z0-9_])" . preg_quote($function, '#') . "{1}\s*\({0,1}#si", $this->file_contents))
{
$return = $this->display_line_code(mpv::ERROR_NOTICE, 'USAGE_' . strtoupper(str_replace(array('_', '$', '('), '', $function)), false, "#(^\s*|[^a-z0-9_])" . preg_quote($function) . "([ \(|\(| ]+)#si");
}
@@ -496,7 +497,7 @@ protected function test_include()
$content_new = substr($content_new, 0, $loc + 2);
}
- if (preg_match("#^(include_once|require_once|include|require)(\s'|\s\"|\s\$|\s\(|\()#", $content_new))
+ if (preg_match("#(include_once|require_once|include|require)(\s'|\s\"|\s\$|\s\(|\()#", $content_new))
{
if (strpos($content_new, '$phpbb_root_path') === false && strpos($content_new, '$phpbb_admin_path') === false)
{
@@ -512,5 +513,6 @@ protected function test_include()
}
}
}
+ return $return;
}
}
View
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit backupGlobals="true"
+ backupStaticAttributes="true"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ processIsolation="false"
+ stopOnFailure="false"
+ syntaxCheck="false"
+ bootstrap="tests/bootstrap.php"
+>
+ <testsuites>
+ <testsuite name="phpBB Test Suite">
+ <directory suffix="_test.php">./tests/</directory>
+ </testsuite>
+ </testsuites>
+
+ <filter>
+ <blacklist>
+ <directory>./tests/</directory>
+ </blacklist>
+ </filter>
+</phpunit>
View
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit backupGlobals="true"
+ backupStaticAttributes="true"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ processIsolation="false"
+ stopOnFailure="false"
+ syntaxCheck="false"
+ bootstrap="tests/bootstrap.php"
+>
+ <testsuites>
+ <testsuite name="phpBB Test Suite">
+ <directory suffix="_test.php">./tests/</directory>
+ </testsuite>
+ </testsuites>
+
+ <groups>
+ <exclude>
+ <group>slow</group>
+ </exclude>
+ </groups>
+
+ <filter>
+ <blacklist>
+ <directory>./tests/</directory>
+ </blacklist>
+ </filter>
+</phpunit>
View
@@ -0,0 +1,13 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2008 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once 'test_framework/phpbb_test_case_helpers.php';
+require_once 'test_framework/phpbb_test_case.php';
+require_once 'includes/tests/test_base.php';
+require_once 'test_framework/mpv_mock.php';
View
@@ -0,0 +1,50 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2008 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once dirname(__FILE__) . '/../../includes/tests/tests_code.php';
+
+class phpbb_binary_test extends phpbb_test_case
+{
+ private $test;
+ public static function provider()
+ {
+ // array(Input -> redirect(), expected triggered error (else false), expected returned result url (else false))
+ return array(
+ array('testcode/noExtension', false, true),
+ array('testcode/ignoreFile.php', false, false),
+ array('testcode/noBinary', 'FILE_NON_BINARY', false),
+ );
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->test = new mpv_tests_code(new mpv);
+ }
+
+ /**
+ * @dataProvider provider
+ */
+ public function test_binary($test, $expected_error, $expected_result)
+ {
+ global $user;
+
+ if ($expected_error !== false)
+ {
+ $this->setExpectedTriggerError(E_USER_ERROR, $expected_error);
+ }
+
+ $result = $this->test->unittest('check_binary', array(('tests/code/' . $test)));
+
+ $this->assertEquals($expected_result, $result);
+
+ }
+}
+
View
@@ -0,0 +1,59 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2008 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once dirname(__FILE__) . '/../../includes/tests/tests_code.php';
+
+class phpbb_mysql_test extends phpbb_test_case
+{
+ private $test;
+ public static function provider()
+ {
+ // array(Input -> redirect(), expected triggered error (else false), expected returned result url (else false))
+ return array(
+ array('testcode/dbal/mysql', 'USAGE_MYSQL', false),
+ array('testcode/dbal/mysqli', 'USAGE_MYSQLI', false),
+ array('testcode/dbal/oci', 'USAGE_OCI', false),
+ array('testcode/dbal/sqlite', 'USAGE_SQLITE', false),
+ array('testcode/dbal/pg', 'USAGE_PG', false),
+ array('testcode/dbal/mssql', 'USAGE_MSSQL', false),
+ array('testcode/dbal/odbc', 'USAGE_ODBC', false),
+ array('testcode/dbal/sqlsrv', 'USAGE_SQLSRV', false),
+ array('testcode/dbal/ibase', 'USAGE_IBASE', false),
+ array('testcode/dbal/db2', 'USAGE_DB2', false),
+ array('testcode/short2', false, true),
+ );
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->test = new mpv_tests_code(new mpv);
+ }
+
+ /**
+ * @dataProvider provider
+ */
+ public function test_mysql($test, $expected_error, $expected_result)
+ {
+ global $user;
+ $this->test->setFilename('tests/code/' . $test);
+
+ if ($expected_error !== false)
+ {
+ $this->setExpectedTriggerError(E_USER_ERROR, $expected_error);
+ }
+
+ $result = $this->test->unittest('test_dbal', array());
+
+ $this->assertEquals($expected_result, $result);
+
+ }
+}
+
View
@@ -0,0 +1,49 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2008 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once dirname(__FILE__) . '/../../includes/tests/tests_code.php';
+
+class phpbb_empty_test extends phpbb_test_case
+{
+ private $test;
+ public static function provider()
+ {
+ // array(Input -> redirect(), expected triggered error (else false), expected returned result url (else false))
+ return array(
+ array('testcode/emptyFile', 'FILE_EMPTY', false),
+ array('testcode/noExtension', false, true),
+ );
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->test = new mpv_tests_code(new mpv);
+ }
+
+ /**
+ * @dataProvider provider
+ */
+ public function test_empty($test, $expected_error, $expected_result)
+ {
+ global $user;
+ $this->test->setFilename('tests/code/' . $test);
+
+ if ($expected_error !== false)
+ {
+ $this->setExpectedTriggerError(E_USER_ERROR, $expected_error);
+ }
+
+ $result = $this->test->unittest('test_empty', array());
+
+ $this->assertEquals($expected_result, $result);
+ }
+}
+
@@ -0,0 +1,68 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2008 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+require_once dirname(__FILE__) . '/../../includes/tests/tests_code.php';
+
+class phpbb_function_test extends phpbb_test_case
+{
+ private $test;
+ public static function provider()
+ {
+ // array(Input -> redirect(), expected triggered error (else false), expected returned result url (else false))
+ return array(
+ array('testcode/dbal/mysql', false, true),
+ array('testcode/functions/eval', 'USAGE_EVAL', false),
+ array('testcode/functions/exec', 'USAGE_EXEC', false),
+ array('testcode/functions/system', 'USAGE_SYSTEM', false),
+ array('testcode/functions/passthru', 'USAGE_PASSTHRU', false),
+ array('testcode/functions/getenv', 'USAGE_GETENV', false),
+ array('testcode/functions/die', 'USAGE_DIE', false),
+ array('testcode/functions/sha1', 'USAGE_SHA1', false),
+ array('testcode/functions/addslashes', 'USAGE_ADDSLASHES', false),
+ array('testcode/functions/stripslashes', 'USAGE_STRIPSLASHES', false),
+
+ array('testcode/functions/backticks', 'USAGE_`', false),
+
+ array('testcode/functions/include_once', 'USAGE_INCLUDEONCE', false),
+ array('testcode/functions/include_once2', 'USAGE_INCLUDEONCE', false),
+ array('testcode/functions/require_once', 'USAGE_REQUIREONCE', false),
+ array('testcode/functions/require_once2', 'USAGE_REQUIREONCE', false),
+ array('testcode/functions/md5', 'USAGE_MD5', false),
+ array('testcode/functions/md52', false, true),
+ array('testcode/short2', false, true),
+ );
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->test = new mpv_tests_code(new mpv);
+ }
+
+ /**
+ * @dataProvider provider
+ */
+ public function test_function($test, $expected_error, $expected_result)
+ {
+ global $user;
+ $this->test->setFilename('tests/code/' . $test);
+
+ if ($expected_error !== false)
+ {
+ $this->setExpectedTriggerError(E_USER_ERROR, $expected_error);
+ }
+
+ $result = $this->test->unittest('test_code', array());
+
+ if ($expected_error === false)
+ $this->assertEquals($expected_result, $result);
+ }
+}
+
Oops, something went wrong.

0 comments on commit 6324547

Please sign in to comment.