Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 632454716d31ca444b1c8964c86ce716ec884173 1 parent aadea7a
@paul999 paul999 authored
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
View
11 includes/tests/test_base.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);
+ }
}
?>
View
10 includes/tests/tests_code.php
@@ -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
25 phpunit.xml.all
@@ -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
31 phpunit.xml.dist
@@ -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
13 tests/bootstrap.php
@@ -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
50 tests/code/binary_test.php
@@ -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
59 tests/code/db_test.php
@@ -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
49 tests/code/empty_test.php
@@ -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);
+ }
+}
+
View
68 tests/code/function_test.php
@@ -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);
+ }
+}
+
View
58 tests/code/in_phpbb_test.php
@@ -0,0 +1,58 @@
+<?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_in_phpbb_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/short1', 'SHORT_TAGS', false),
+ array('testcode/short2', 'SHORT_TAGS', false),
+ array('testcode/short3', 'SHORT_TAGS', false),
+ array('testcode/short4', 'SHORT_TAGS', false),*/
+ array('mcp/info/mcp_test.php', false, true),
+ array('acp/info/acp_test.php', false, true),
+ array('ucp/info/ucp_test.php', false, true),
+ array('testcode/inphpbb.php', false, true),
+ array('testcode/inphpbb3.php', false, true),
+ array('testcode/phpbb.php', false, true),
+ array('testcode/noinphpbb.php', 'NO_IN_PHPBB', false),
+ );
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->test = new mpv_tests_code(new mpv);
+ }
+
+ /**
+ * @dataProvider provider
+ */
+ public function test_in_phpbb($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_in_phpbb', array());
+
+ $this->assertEquals($expected_result, $result);
+ }
+}
+
View
64 tests/code/include_test.php
@@ -0,0 +1,64 @@
+<?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_include_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/include/include1', 'INCLUDE_NO_ROOT', false),
+ array('testcode/include/includeonce1', 'INCLUDE_NO_ROOT', false),
+ array('testcode/include/require1', 'INCLUDE_NO_ROOT', false),
+ array('testcode/include/requireonce1', 'INCLUDE_NO_ROOT', false),
+
+ array('testcode/include/include2', 'INCLUDE_NO_PHP', false),
+ array('testcode/include/includeonce2', 'INCLUDE_NO_PHP', false),
+ array('testcode/include/require2', 'INCLUDE_NO_PHP', false),
+ array('testcode/include/requireonce2', 'INCLUDE_NO_PHP', false),
+
+ array('testcode/include/include3', false, true),
+ array('testcode/include/include4', 'INCLUDE_NO_ROOT', false),
+ array('testcode/include/include5', 'INCLUDE_NO_PHP', false),
+ array('testcode/include/include6', false, true),
+ array('testcode/include/include7', 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_include($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_include', array());
+
+ $this->assertEquals($expected_result, $result);
+ }
+}
+
View
51 tests/code/request_var_test.php
@@ -0,0 +1,51 @@
+<?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_request_var_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/requestVar1', false, true),
+ array('testcode/requestVar2', 'USAGE_REQUEST_VAR_INT', false),
+ array('testcode/requestVar3', 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_request_var($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_request_var', array());
+
+ $this->assertEquals($expected_result, $result);
+ }
+}
+
View
52 tests/code/short_test.php
@@ -0,0 +1,52 @@
+<?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_short_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/short1', 'SHORT_TAGS', false),
+ array('testcode/short2', 'SHORT_TAGS', false),
+ array('testcode/short3', 'SHORT_TAGS', false),
+ array('testcode/short4', 'SHORT_TAGS', false),
+ array('testcode/noShort', false, true),
+ );
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->test = new mpv_tests_code(new mpv);
+ }
+
+ /**
+ * @dataProvider provider
+ */
+ public function test_short($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_short_tags', array());
+
+ $this->assertEquals($expected_result, $result);
+ }
+}
+
View
1  tests/code/testcode/dbal/db2
@@ -0,0 +1 @@
+db2_connect();
View
1  tests/code/testcode/dbal/ibase
@@ -0,0 +1 @@
+ibase_connect();
View
1  tests/code/testcode/dbal/mssql
@@ -0,0 +1 @@
+mssql_connect();
View
1  tests/code/testcode/dbal/mysql
@@ -0,0 +1 @@
+mysql_connect();
View
1  tests/code/testcode/dbal/mysqli
@@ -0,0 +1 @@
+mysqli_connect();
View
1  tests/code/testcode/dbal/oci
@@ -0,0 +1 @@
+oci_connect();
View
1  tests/code/testcode/dbal/odbc
@@ -0,0 +1 @@
+odbc_connect();
View
1  tests/code/testcode/dbal/pg
@@ -0,0 +1 @@
+pg_connect();
View
1  tests/code/testcode/dbal/sqlite
@@ -0,0 +1 @@
+sqlite_connect();
View
1  tests/code/testcode/dbal/sqlsrv
@@ -0,0 +1 @@
+sqlsrv_connect();
View
0  tests/code/testcode/emptyFile
No changes.
View
1  tests/code/testcode/functions/addslashes
@@ -0,0 +1 @@
+addslashes();
View
1  tests/code/testcode/functions/backticks
@@ -0,0 +1 @@
+`test`
View
1  tests/code/testcode/functions/die
@@ -0,0 +1 @@
+die();
View
1  tests/code/testcode/functions/eval
@@ -0,0 +1 @@
+eval();
View
1  tests/code/testcode/functions/exec
@@ -0,0 +1 @@
+exec();
View
1  tests/code/testcode/functions/getenv
@@ -0,0 +1 @@
+getenv();
View
1  tests/code/testcode/functions/include_once
@@ -0,0 +1 @@
+include_once();
View
1  tests/code/testcode/functions/include_once2
@@ -0,0 +1 @@
+include_once '';
View
1  tests/code/testcode/functions/md5
@@ -0,0 +1 @@
+md5();
View
8 tests/code/testcode/functions/md52
@@ -0,0 +1,8 @@
+<?php
+ if (phpbb_gallery_url::_file_exists($import_schema, 'import', ''))
+ {
+ include(phpbb_gallery_url::_return_file($import_schema, 'import', ''));
+ // Replace the md5 with the ' again and remove the space at the end to prevent \' troubles
+ $user_data['username'] = utf8_substr(str_replace("{{$import_schema}}", "'", $user_data['username']), 0, -1);
+ $image_name = utf8_substr(str_replace("{{$import_schema}}", "'", $image_name), 0, -1);
+ }
View
1  tests/code/testcode/functions/passthru
@@ -0,0 +1 @@
+passthru();
View
1  tests/code/testcode/functions/require_once
@@ -0,0 +1 @@
+require_once();
View
1  tests/code/testcode/functions/require_once2
@@ -0,0 +1 @@
+require_once 'file';
View
1  tests/code/testcode/functions/sha1
@@ -0,0 +1 @@
+sha1();
View
1  tests/code/testcode/functions/stripslashes
@@ -0,0 +1 @@
+stripslashes();
View
1  tests/code/testcode/functions/system
@@ -0,0 +1 @@
+system();
View
3  tests/code/testcode/include/include1
@@ -0,0 +1,3 @@
+<?php
+include('test.' . $phpEx);
+?>
View
3  tests/code/testcode/include/include2
@@ -0,0 +1,3 @@
+<?php
+include($phpbb_root_path . 'test.php');
+?>
View
3  tests/code/testcode/include/include3
@@ -0,0 +1,3 @@
+<?php
+include($phpbb_root_path . 'test.' . $phpEx);
+?>
View
6 tests/code/testcode/include/include4
@@ -0,0 +1,6 @@
+<?php
+if (test)
+{
+ include('test.' . $phpEx);
+}
+?>
View
6 tests/code/testcode/include/include5
@@ -0,0 +1,6 @@
+<?php
+if (test)
+{
+ include($phpbb_root_path . 'test.php');
+}
+?>
View
3  tests/code/testcode/include/include6
@@ -0,0 +1,3 @@
+<?php
+_include('');
+?>
View
3  tests/code/testcode/include/include7
@@ -0,0 +1,3 @@
+<?php
+// This comment has include in it.
+?>
View
3  tests/code/testcode/include/includeonce1
@@ -0,0 +1,3 @@
+<?php
+include_once('test.' . $phpEx);
+?>
View
3  tests/code/testcode/include/includeonce2
@@ -0,0 +1,3 @@
+<?php
+include_once($phpbb_root_path . 'test.php');
+?>
View
3  tests/code/testcode/include/require1
@@ -0,0 +1,3 @@
+<?php
+require('test.' . $phpEx);
+?>
View
3  tests/code/testcode/include/require2
@@ -0,0 +1,3 @@
+<?php
+require($phpbb_root_path . 'test.php');
+?>
View
3  tests/code/testcode/include/requireonce1
@@ -0,0 +1,3 @@
+<?php
+require_once('test.' . $phpEx);
+?>
View
3  tests/code/testcode/include/requireonce2
@@ -0,0 +1,3 @@
+<?php
+require_once($phpbb_root_path . 'test.php');
+?>
View
3  tests/code/testcode/inphpbb.php
@@ -0,0 +1,3 @@
+<?php
+define('IN_PHPBB', true);
+?>
View
3  tests/code/testcode/inphpbb3.php
@@ -0,0 +1,3 @@
+<?php
+define ('IN_PHPBB', true);
+?>
View
1  tests/code/testcode/noBinary
@@ -0,0 +1 @@
+This is only a textfile
View
2  tests/code/testcode/noExtension
@@ -0,0 +1,2 @@
+This is a binary file.
+�
View
3  tests/code/testcode/noShort
@@ -0,0 +1,3 @@
+<?php
+
+?>
View
3  tests/code/testcode/noinphpbb.php
@@ -0,0 +1,3 @@
+<?php
+
+?>
View
6 tests/code/testcode/phpbb.php
@@ -0,0 +1,6 @@
+<?php
+if (!defined('IN_PHPBB'))
+{
+
+}
+?>
View
5 tests/code/testcode/requestVar1
@@ -0,0 +1,5 @@
+<?php
+
+$string = request_var('test', '');
+
+?>
View
5 tests/code/testcode/requestVar2
@@ -0,0 +1,5 @@
+<?php
+
+$string = request_var('test', '1');
+
+?>
View
5 tests/code/testcode/requestVar3
@@ -0,0 +1,5 @@
+<?php
+
+$string = request_var('test', 1);
+
+?>
View
2  tests/code/testcode/short1
@@ -0,0 +1,2 @@
+<?
+?>
View
2  tests/code/testcode/short2
@@ -0,0 +1,2 @@
+<?
+?>
View
2  tests/code/testcode/short3
@@ -0,0 +1,2 @@
+<?
+?>
View
3  tests/code/testcode/short4
@@ -0,0 +1,3 @@
+<?=
+
+?>
View
5 tests/code/testcode/unixFile
@@ -0,0 +1,5 @@
+This is a file with UNIX line ends
+This is a file with UNIX line ends
+This is a file with UNIX line ends
+This is a file with UNIX line ends
+This is a file with UNIX line ends
View
5 tests/code/testcode/windowsFile
@@ -0,0 +1,5 @@
+This is a file with windows line ends
+This is a file with windows line ends
+This is a file with windows line ends
+This is a file with windows line ends
+This is a file with windows line ends
View
49 tests/code/unix_test.php
@@ -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_unix_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/windowsFile', 'NO_UNIX_ENDINGS', false),
+ array('testcode/unixFile', false, true),
+ );
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->test = new mpv_tests_code(new mpv);
+ }
+
+ /**
+ * @dataProvider provider
+ */
+ public function test_unix($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_unix_endings', array());
+
+ $this->assertEquals($expected_result, $result);
+ }
+}
+
View
37 tests/test_framework/mpv_mock.php
@@ -0,0 +1,37 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2008 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+class mpv
+{
+ /**
+ * Constant for "fail" error
+ */
+ const ERROR_FAIL = 1;
+
+ /**
+ * Constant for notices
+ */
+ const ERROR_NOTICE = 2;
+
+ /**
+ * Constant for warnings
+ */
+ const ERROR_WARNING = 3;
+
+ /**
+ * Constant for information notices
+ */
+ const ERROR_INFO = 4;
+
+ public function push_error($type, $message)
+ {
+ trigger_error($message, E_USER_ERROR);
+ }
+}
+?>
View
43 tests/test_framework/phpbb_test_case.php
@@ -0,0 +1,43 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2008 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+class phpbb_test_case extends PHPUnit_Framework_TestCase
+{
+ protected $test_case_helpers;
+
+ public function __construct($name = NULL, array $data = array(), $dataName = '')
+ {
+ parent::__construct($name, $data, $dataName);
+ $this->backupStaticAttributesBlacklist += array(
+ 'PHP_CodeCoverage' => array('instance'),
+ 'PHP_CodeCoverage_Filter' => array('instance'),
+ 'PHP_CodeCoverage_Util' => array('ignoredLines', 'templateMethods'),
+ 'PHP_Timer' => array('startTimes',),
+ 'PHP_Token_Stream' => array('customTokens'),
+ 'PHP_Token_Stream_CachingFactory' => array('cache'),
+
+ 'phpbb_database_test_case' => array('already_connected'),
+ );
+ }
+
+ public function get_test_case_helpers()
+ {
+ if (!$this->test_case_helpers)
+ {
+ $this->test_case_helpers = new phpbb_test_case_helpers($this);
+ }
+
+ return $this->test_case_helpers;
+ }
+
+ public function setExpectedTriggerError($errno, $message = '')
+ {
+ $this->get_test_case_helpers()->setExpectedTriggerError($errno, $message);
+ }
+}
View
44 tests/test_framework/phpbb_test_case_helpers.php
@@ -0,0 +1,44 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2008 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+class phpbb_test_case_helpers
+{
+ protected $expectedTriggerError = false;
+
+ protected $test_case;
+
+ public function __construct($test_case)
+ {
+ $this->test_case = $test_case;
+ }
+
+ public function setExpectedTriggerError($errno, $message = '')
+ {
+ $exceptionName = '';
+ switch ($errno)
+ {
+ case E_NOTICE:
+ case E_STRICT:
+ PHPUnit_Framework_Error_Notice::$enabled = true;
+ $exceptionName = 'PHPUnit_Framework_Error_Notice';
+ break;
+
+ case E_WARNING:
+ PHPUnit_Framework_Error_Warning::$enabled = true;
+ $exceptionName = 'PHPUnit_Framework_Error_Warning';
+ break;
+
+ default:
+ $exceptionName = 'PHPUnit_Framework_Error';
+ break;
+ }
+ $this->expectedTriggerError = true;
+ $this->test_case->setExpectedException($exceptionName, (string) $message, $errno);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.