From 51347ebc09d18a55fa93fe86ef50a215148c935f Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 29 Apr 2012 00:30:08 +0300 Subject: [ticket/10800] Changing template paths in tests Changing template paths in tests from absolute to relative PHPBB3-10800 --- tests/template/template_includejs_test.php | 7 +++---- tests/template/template_locate_test.php | 6 +++--- tests/template/template_test.php | 2 +- tests/template/template_test_case.php | 4 +++- tests/template/template_test_case_with_tree.php | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/template/template_includejs_test.php b/tests/template/template_includejs_test.php index 632fde61d1..d80254072b 100644 --- a/tests/template/template_includejs_test.php +++ b/tests/template/template_includejs_test.php @@ -17,11 +17,10 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes $this->setup_engine(array('assets_version' => 1)); // Prepare correct result - $dir = dirname(__FILE__); $scripts = array( - '', - '', - '' + '', + '', + '' ); // Run test diff --git a/tests/template/template_locate_test.php b/tests/template/template_locate_test.php index d6e2e82a47..be9ae06809 100644 --- a/tests/template/template_locate_test.php +++ b/tests/template/template_locate_test.php @@ -17,21 +17,21 @@ class phpbb_template_template_locate_test extends phpbb_template_template_test_c // First element of the array is test name - keep them distinct array( 'simple inheritance - only parent template exists', - dirname(__FILE__) . '/parent_templates/parent_only.html', + $this->test_path . '/parent_templates/parent_only.html', 'parent_only.html', false, true, ), array( 'simple inheritance - only child template exists', - dirname(__FILE__) . '/templates/child_only.html', + $this->test_path . '/templates/child_only.html', 'child_only.html', false, true, ), array( 'simple inheritance - both parent and child templates exist', - dirname(__FILE__) . '/templates/parent_and_child.html', + $this->test_path . '/templates/parent_and_child.html', 'parent_and_child.html', false, true, diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 739bbe9387..f8677ed913 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -277,7 +277,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case $this->template->set_filenames(array('test' => $filename)); $this->assertFileNotExists($this->template_path . '/' . $filename, 'Testing missing file, file cannot exist'); - $expecting = sprintf('style resource locator: File for handle test does not exist. Could not find: %s', realpath($this->template_path . '/../') . '/templates/' . $filename); + $expecting = sprintf('style resource locator: File for handle test does not exist. Could not find: %s', $this->test_path . '/templates/' . $filename); $this->setExpectedTriggerError(E_USER_ERROR, $expecting); $this->display('test'); diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index d660aa3f56..dd0acba6cd 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -18,6 +18,8 @@ class phpbb_template_template_test_case extends phpbb_test_case protected $style_resource_locator; protected $style_provider; + protected $test_path = 'tests/template'; + // Keep the contents of the cache for debugging? const PRESERVE_CACHE = true; @@ -63,7 +65,7 @@ class phpbb_template_template_test_case extends phpbb_test_case $defaults = $this->config_defaults(); $config = new phpbb_config(array_merge($defaults, $new_config)); - $this->template_path = dirname(__FILE__) . '/templates'; + $this->template_path = $this->test_path . '/templates'; $this->style_resource_locator = new phpbb_style_resource_locator(); $this->style_provider = new phpbb_style_path_provider(); $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator); diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php index 9522c97330..05ccb7ee55 100644 --- a/tests/template/template_test_case_with_tree.php +++ b/tests/template/template_test_case_with_tree.php @@ -18,8 +18,8 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat $defaults = $this->config_defaults(); $config = new phpbb_config(array_merge($defaults, $new_config)); - $this->template_path = dirname(__FILE__) . '/templates'; - $this->parent_template_path = dirname(__FILE__) . '/parent_templates'; + $this->template_path = $this->test_path . '/templates'; + $this->parent_template_path = $this->test_path . '/parent_templates'; $this->style_resource_locator = new phpbb_style_resource_locator(); $this->style_provider = new phpbb_style_path_provider(); $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator); -- cgit v1.2.1 From 5114edcafe440df04357d789c03b390d6da48db5 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Tue, 1 May 2012 17:41:46 +0300 Subject: [ticket/10800] Changing html to js for includejs tests Changing .html to .js files for includejs tests PHPBB3-10800 --- tests/template/parent_templates/parent_and_child.js | 1 + tests/template/parent_templates/parent_only.js | 1 + tests/template/template_includejs_test.php | 8 ++++---- tests/template/templates/child_only.js | 1 + tests/template/templates/includejs.html | 4 ++-- tests/template/templates/parent_and_child.js | 1 + 6 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 tests/template/parent_templates/parent_and_child.js create mode 100644 tests/template/parent_templates/parent_only.js create mode 100644 tests/template/templates/child_only.js create mode 100644 tests/template/templates/parent_and_child.js (limited to 'tests') diff --git a/tests/template/parent_templates/parent_and_child.js b/tests/template/parent_templates/parent_and_child.js new file mode 100644 index 0000000000..6d9bb163bf --- /dev/null +++ b/tests/template/parent_templates/parent_and_child.js @@ -0,0 +1 @@ +// JavaScript file in a parent style. diff --git a/tests/template/parent_templates/parent_only.js b/tests/template/parent_templates/parent_only.js new file mode 100644 index 0000000000..9c3007d83f --- /dev/null +++ b/tests/template/parent_templates/parent_only.js @@ -0,0 +1 @@ +// JavaScript file only in parent style. diff --git a/tests/template/template_includejs_test.php b/tests/template/template_includejs_test.php index d80254072b..a8f9a9037f 100644 --- a/tests/template/template_includejs_test.php +++ b/tests/template/template_includejs_test.php @@ -18,13 +18,13 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes // Prepare correct result $scripts = array( - '', - '', - '' + '', + '', + '' ); // Run test $cache_file = $this->template->cachepath . 'includejs.html.php'; - $this->run_template('includejs.html', array('PARENT' => 'parent_only.html'), array(), array(), implode('', $scripts), $cache_file); + $this->run_template('includejs.html', array('PARENT' => 'parent_only.js'), array(), array(), implode('', $scripts), $cache_file); } } diff --git a/tests/template/templates/child_only.js b/tests/template/templates/child_only.js new file mode 100644 index 0000000000..542b26526c --- /dev/null +++ b/tests/template/templates/child_only.js @@ -0,0 +1 @@ +// JavaScript file only in a child style. diff --git a/tests/template/templates/includejs.html b/tests/template/templates/includejs.html index 186fc30b43..8a2587d76b 100644 --- a/tests/template/templates/includejs.html +++ b/tests/template/templates/includejs.html @@ -1,5 +1,5 @@ - + - + {SCRIPTS} \ No newline at end of file diff --git a/tests/template/templates/parent_and_child.js b/tests/template/templates/parent_and_child.js new file mode 100644 index 0000000000..d544d94d83 --- /dev/null +++ b/tests/template/templates/parent_and_child.js @@ -0,0 +1 @@ +// JavaScript file in a child style. -- cgit v1.2.1 From 5b96b5fce7283ebd52f88ef6daa3c8233a7df1ec Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 7 May 2012 10:39:49 -0400 Subject: [ticket/10837] Removed tearDownAfterClass() from extension_controller_test.php PHPBB3-10837 --- tests/functional/extension_controller_test.php | 9 --------- 1 file changed, 9 deletions(-) (limited to 'tests') diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 4ee0e68718..e9409d9d3f 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -65,15 +65,6 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c } } - public static function tearDownAfterClass() - { - $phpbb_root_path = self::$config['phpbb_functional_path']; - - // @todo delete the fixtures from the $phpbb_root_path board - // Note that it might be best to find a public domain function - // and port it into here instead of writing it from scratch - } - public function setUp() { parent::setUp(); -- cgit v1.2.1 From d578eff712b6376e3568965afec7054bff317127 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Tue, 28 Feb 2012 06:18:24 -0600 Subject: [ticket/10678] Add better support for Firebird, Oracle, and MSSQL Allow ODBC connections for Firebird Capitalize fixture tables and columns for Firebird On database drop failure, drop all tables Provide cleanup utilities for databases that cannot be dropped PHPBB3-10678 --- tests/RUNNING_TESTS.txt | 19 ++++ .../phpbb_database_connection_helper.php | 24 +++++ tests/test_framework/phpbb_database_test_case.php | 27 ++++++ .../phpbb_database_test_connection_manager.php | 106 ++++++++++++++++++++- 4 files changed, 171 insertions(+), 5 deletions(-) create mode 100644 tests/test_framework/phpbb_database_connection_helper.php (limited to 'tests') diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt index 59197acc0f..705fb28d07 100644 --- a/tests/RUNNING_TESTS.txt +++ b/tests/RUNNING_TESTS.txt @@ -43,6 +43,25 @@ will run phpunit with the same parameters as in the shown test_config.php file: PHPBB_TEST_DBNAME='database' PHPBB_TEST_DBUSER='user' \ PHPBB_TEST_DBPASSWD='password' phpunit +Special Database Cases +---------------------- +In order to run tests on some of the databases that we support, it will be +necessary to provide a custom DSN string in test_config.php. This is only needed for +MSSQL 2000+ (PHP module), MSSQL via ODBC, and Firebird when PDO_Firebird does not work +on your system (https://bugs.php.net/bug.php?id=61183). The variable must be named $custom_dsn. + +Examples: +Firebird using http://www.firebirdsql.org/en/odbc-driver/ +$custom_dsn = "Driver={Firebird/InterBase(r) driver};dbname=$dbhost:$dbname"; + +MSSQL +$custom_dsn = "Driver={SQL Server Native Client 10.0};Server=$dbhost;Database=$dbname"; + +The other fields in test_config.php should be filled out as you would normally to connect +to that database in phpBB. + +Additionally, you will need to be running the DbUnit fork from https://github.com/phpbb/dbunit/tree/phpbb. + Running ======= diff --git a/tests/test_framework/phpbb_database_connection_helper.php b/tests/test_framework/phpbb_database_connection_helper.php new file mode 100644 index 0000000000..e1c50655ed --- /dev/null +++ b/tests/test_framework/phpbb_database_connection_helper.php @@ -0,0 +1,24 @@ +driver = $dbms; + $this->version = (double)$version; + + parent::__construct($dsn, $user, $pass); + } +} \ No newline at end of file diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index e742b543b0..0e5518fef8 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -28,6 +28,28 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test ); } + public function createXMLDataSet($path) + { + $db_config = $this->get_database_config(); + + //Firebird requires table and column names to be uppercase + if($db_config['dbms'] == 'firebird') + { + $xml_data = file_get_contents($path); + $xml_data = preg_replace_callback('/(?:())/', 'phpbb_database_test_case::to_upper', $xml_data); + $xml_data = preg_replace_callback('/(?:())([a-z_]+)(?:(<\/column>))/', 'phpbb_database_test_case::to_upper', $xml_data); + + $temp = tmpfile(); + fwrite($temp, $xml_data); + fseek($temp, 0); + + $meta_data = stream_get_meta_data($temp); + $path = $meta_data['uri']; + } + + return parent::createXMLDataSet($path); + } + public function get_test_case_helpers() { if (!$this->test_case_helpers) @@ -106,4 +128,9 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test { return new phpbb_database_test_connection_manager($config); } + + public static function to_upper($matches) + { + return $matches[1] . strtoupper($matches[2]) . $matches[3]; + } } diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index c734c90a1a..328d90fca9 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -8,6 +8,7 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_install.php'; +require_once 'phpbb_database_connection_helper.php'; class phpbb_database_test_connection_manager { @@ -83,9 +84,37 @@ class phpbb_database_test_connection_manager break; } + //These require different connection strings on the phpBB side than they do in PDO + //so you must provide a DSN string for ODBC separately + if($this->config['dbms'] == 'mssql' || $this->config['dbms'] == 'firebird') + { + if(!empty($this->config['custom_dsn'])) + { + $dsn = 'odbc:' . $this->config['custom_dsn']; + } + } + try { - $this->pdo = new PDO($dsn, $this->config['dbuser'], $this->config['dbpasswd']); + switch($this->config['dbms']) + { + case 'mssql': + case 'mssql_odbc': + $this->pdo = new phpbb_database_connection_ODBC_PDO_wrapper('mssql', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']); + break; + + case 'firebird': + if(!empty($this->config['custom_dsn'])) + { + $this->pdo = new phpbb_database_connection_ODBC_PDO_wrapper('firebird', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']); + break; + } + //Fall through if they're using the firebird PDO driver and not the generic ODBC driver + + default: + $this->pdo = new PDO($dsn, $this->config['dbuser'], $this->config['dbpasswd']); + break; + } } catch (PDOException $e) { @@ -93,8 +122,7 @@ class phpbb_database_test_connection_manager throw new Exception("Unable do connect to $cleaned_dsn using PDO with error: {$e->getMessage()}"); } - // good for debug - // $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } /** @@ -125,12 +153,41 @@ class phpbb_database_test_connection_manager } break; + case 'firebird': + $this->connect(); + // Drop all of the tables + foreach ($this->get_tables() as $table) + { + $this->pdo->exec('DROP TABLE ' . $table); + } + $this->purge_extras(); + break; + + case 'oracle': + $this->connect(); + // Drop all of the tables + foreach ($this->get_tables() as $table) + { + $this->pdo->exec('DROP TABLE ' . $table . ' CASCADE CONSTRAINTS'); + } + $this->purge_extras(); + break; + default: $this->connect(false); try { $this->pdo->exec('DROP DATABASE ' . $this->config['dbname']); + + try + { + $this->pdo->exec('CREATE DATABASE ' . $this->config['dbname']); + } + catch (PDOException $e) + { + throw new Exception("Unable to re-create database: {$e->getMessage()}"); + } } catch (PDOException $e) { @@ -139,9 +196,8 @@ class phpbb_database_test_connection_manager { $this->pdo->exec('DROP TABLE ' . $table); } + $this->purge_extras(); } - - $this->pdo->exec('CREATE DATABASE ' . $this->config['dbname']); break; } } @@ -317,4 +373,44 @@ class phpbb_database_test_connection_manager throw new Exception($message); } } + + /** + * Removes extra objects from a database. This is for cases where dropping the database fails. + */ + public function purge_extras() + { + $this->ensure_connected(__METHOD__); + $queries = array(); + + switch ($this->config['dbms']) + { + case 'firebird': + $sql = 'SELECT RDB$GENERATOR_NAME + FROM RDB$GENERATORS + WHERE RDB$SYSTEM_FLAG = 0'; + $result = $this->pdo->query($sql); + + while ($row = $result->fetch(PDO::FETCH_NUM)) + { + $queries[] = 'DROP GENERATOR ' . current($row); + } + break; + + case 'oracle': + $sql = 'SELECT sequence_name + FROM USER_SEQUENCES'; + $result = $this->pdo->query($sql); + + while ($row = $result->fetch(PDO::FETCH_NUM)) + { + $queries[] = 'DROP SEQUENCE ' . current($row); + } + break; + } + + foreach($queries as $query) + { + $this->pdo->exec($query); + } + } } -- cgit v1.2.1 From 5cbe919256a0046a896a88c47b96276b6d7c05d0 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Tue, 28 Feb 2012 13:47:15 -0600 Subject: [ticket/10678] Fix formatting PHPBB3-10678 --- tests/test_framework/phpbb_database_connection_helper.php | 10 +++++++++- tests/test_framework/phpbb_database_test_case.php | 2 +- .../test_framework/phpbb_database_test_connection_manager.php | 10 +++++----- 3 files changed, 15 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_database_connection_helper.php b/tests/test_framework/phpbb_database_connection_helper.php index e1c50655ed..6ba527b5d9 100644 --- a/tests/test_framework/phpbb_database_connection_helper.php +++ b/tests/test_framework/phpbb_database_connection_helper.php @@ -1,4 +1,12 @@ get_database_config(); //Firebird requires table and column names to be uppercase - if($db_config['dbms'] == 'firebird') + if ($db_config['dbms'] == 'firebird') { $xml_data = file_get_contents($path); $xml_data = preg_replace_callback('/(?:(
))/', 'phpbb_database_test_case::to_upper', $xml_data); diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 328d90fca9..6e3f602ab7 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -86,9 +86,9 @@ class phpbb_database_test_connection_manager //These require different connection strings on the phpBB side than they do in PDO //so you must provide a DSN string for ODBC separately - if($this->config['dbms'] == 'mssql' || $this->config['dbms'] == 'firebird') + if ($this->config['dbms'] == 'mssql' || $this->config['dbms'] == 'firebird') { - if(!empty($this->config['custom_dsn'])) + if (!empty($this->config['custom_dsn'])) { $dsn = 'odbc:' . $this->config['custom_dsn']; } @@ -96,7 +96,7 @@ class phpbb_database_test_connection_manager try { - switch($this->config['dbms']) + switch ($this->config['dbms']) { case 'mssql': case 'mssql_odbc': @@ -104,7 +104,7 @@ class phpbb_database_test_connection_manager break; case 'firebird': - if(!empty($this->config['custom_dsn'])) + if (!empty($this->config['custom_dsn'])) { $this->pdo = new phpbb_database_connection_ODBC_PDO_wrapper('firebird', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']); break; @@ -408,7 +408,7 @@ class phpbb_database_test_connection_manager break; } - foreach($queries as $query) + foreach ($queries as $query) { $this->pdo->exec($query); } -- cgit v1.2.1 From 0a596c4b8c4d003d0c8af79af65cb5264e9754fe Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Sun, 4 Mar 2012 17:19:33 -0600 Subject: [ticket/10678] More formatting requests PHPBB3-10678 --- tests/test_framework/phpbb_database_connection_helper.php | 4 ++-- tests/test_framework/phpbb_database_test_connection_manager.php | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_database_connection_helper.php b/tests/test_framework/phpbb_database_connection_helper.php index 6ba527b5d9..fbb85784f8 100644 --- a/tests/test_framework/phpbb_database_connection_helper.php +++ b/tests/test_framework/phpbb_database_connection_helper.php @@ -16,10 +16,10 @@ */ class phpbb_database_connection_ODBC_PDO_wrapper extends PDO { - //Name of the driver being used (i.e. mssql, firebird) + // Name of the driver being used (i.e. mssql, firebird) public $driver = ''; - //Version number of driver since PDO::getAttribute(PDO::ATTR_CLIENT_VERSION) is pretty useless for this + // Version number of driver since PDO::getAttribute(PDO::ATTR_CLIENT_VERSION) is pretty useless for this public $version = 0; function __construct($dbms, $version, $dsn, $user, $pass) diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 6e3f602ab7..2334e08f78 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -8,7 +8,7 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_install.php'; -require_once 'phpbb_database_connection_helper.php'; +require_once dirname(__FILE__) . '/phpbb_database_connection_helper.php'; class phpbb_database_test_connection_manager { @@ -86,12 +86,9 @@ class phpbb_database_test_connection_manager //These require different connection strings on the phpBB side than they do in PDO //so you must provide a DSN string for ODBC separately - if ($this->config['dbms'] == 'mssql' || $this->config['dbms'] == 'firebird') + if (!empty($this->config['custom_dsn']) && ($this->config['dbms'] == 'mssql' || $this->config['dbms'] == 'firebird')) { - if (!empty($this->config['custom_dsn'])) - { - $dsn = 'odbc:' . $this->config['custom_dsn']; - } + $dsn = 'odbc:' . $this->config['custom_dsn']; } try -- cgit v1.2.1 From 9bb2785da0c84bcc4a95f737b7da14c58c5d4380 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Mon, 2 Apr 2012 05:57:48 -0500 Subject: [ticket/10678] More formatting and docblocks PHPBB3-10678 --- tests/test_framework/phpbb_database_test_case.php | 10 +++++++++- .../test_framework/phpbb_database_test_connection_manager.php | 6 +++--- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index b8be6a852a..53c3702aa6 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -32,7 +32,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test { $db_config = $this->get_database_config(); - //Firebird requires table and column names to be uppercase + // Firebird requires table and column names to be uppercase if ($db_config['dbms'] == 'firebird') { $xml_data = file_get_contents($path); @@ -129,6 +129,14 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test return new phpbb_database_test_connection_manager($config); } + /** + * Converts a match in the middle of a string to uppercase. + * This is necessary for tranforming the fixture information for Firebird tests + * + * @param $matches The array of matches from a regular expression + * + * @return string The string with the specified match converted to uppercase + */ public static function to_upper($matches) { return $matches[1] . strtoupper($matches[2]) . $matches[3]; diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 2334e08f78..3c4a112d0d 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -84,8 +84,8 @@ class phpbb_database_test_connection_manager break; } - //These require different connection strings on the phpBB side than they do in PDO - //so you must provide a DSN string for ODBC separately + // These require different connection strings on the phpBB side than they do in PDO + // so you must provide a DSN string for ODBC separately if (!empty($this->config['custom_dsn']) && ($this->config['dbms'] == 'mssql' || $this->config['dbms'] == 'firebird')) { $dsn = 'odbc:' . $this->config['custom_dsn']; @@ -106,7 +106,7 @@ class phpbb_database_test_connection_manager $this->pdo = new phpbb_database_connection_ODBC_PDO_wrapper('firebird', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']); break; } - //Fall through if they're using the firebird PDO driver and not the generic ODBC driver + // Fall through if they're using the firebird PDO driver and not the generic ODBC driver default: $this->pdo = new PDO($dsn, $this->config['dbuser'], $this->config['dbpasswd']); -- cgit v1.2.1 From ceacb63abfdc8144ce88c0d9ce763ccc74836be5 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Thu, 12 Apr 2012 20:10:20 -0500 Subject: [ticket/10678] Lowercase class name, adjust comment width PHPBB3-10678 --- tests/RUNNING_TESTS.txt | 26 +++++++++++++--------- .../phpbb_database_connection_helper.php | 2 +- .../phpbb_database_test_connection_manager.php | 4 ++-- 3 files changed, 18 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt index 705fb28d07..487320f736 100644 --- a/tests/RUNNING_TESTS.txt +++ b/tests/RUNNING_TESTS.txt @@ -36,8 +36,9 @@ found on the wiki (see below). $dbuser = 'user'; $dbpasswd = 'password'; -Alternatively you can specify parameters in the environment, so e.g. the following -will run phpunit with the same parameters as in the shown test_config.php file: +Alternatively you can specify parameters in the environment, so e.g. the +following will run phpunit with the same parameters as in the shown +test_config.php file: $ PHPBB_TEST_DBMS='mysqli' PHPBB_TEST_DBHOST='localhost' \ PHPBB_TEST_DBNAME='database' PHPBB_TEST_DBUSER='user' \ @@ -46,9 +47,10 @@ will run phpunit with the same parameters as in the shown test_config.php file: Special Database Cases ---------------------- In order to run tests on some of the databases that we support, it will be -necessary to provide a custom DSN string in test_config.php. This is only needed for -MSSQL 2000+ (PHP module), MSSQL via ODBC, and Firebird when PDO_Firebird does not work -on your system (https://bugs.php.net/bug.php?id=61183). The variable must be named $custom_dsn. +necessary to provide a custom DSN string in test_config.php. This is only +needed for MSSQL 2000+ (PHP module), MSSQL via ODBC, and Firebird when +PDO_Firebird does not work on your system +(https://bugs.php.net/bug.php?id=61183). The variable must be named $custom_dsn. Examples: Firebird using http://www.firebirdsql.org/en/odbc-driver/ @@ -57,15 +59,17 @@ $custom_dsn = "Driver={Firebird/InterBase(r) driver};dbname=$dbhost:$dbname"; MSSQL $custom_dsn = "Driver={SQL Server Native Client 10.0};Server=$dbhost;Database=$dbname"; -The other fields in test_config.php should be filled out as you would normally to connect -to that database in phpBB. +The other fields in test_config.php should be filled out as you would normally +to connect to that database in phpBB. -Additionally, you will need to be running the DbUnit fork from https://github.com/phpbb/dbunit/tree/phpbb. +Additionally, you will need to be running the DbUnit fork from +https://github.com/phpbb/dbunit/tree/phpbb. Running ======= -Once the prerequisites are installed, run the tests from the project root directory (above phpBB): +Once the prerequisites are installed, run the tests from the project root +directory (above phpBB): $ phpunit @@ -73,8 +77,8 @@ Slow tests -------------- Certain tests, such as the UTF-8 normalizer or the DNS tests tend to be slow. Thus these tests are in the `slow` group, which is excluded by default. You can -enable slow tests by copying the phpunit.xml.all file to phpunit.xml. If you only -want the slow tests, run: +enable slow tests by copying the phpunit.xml.all file to phpunit.xml. If you +only want the slow tests, run: $ phpunit --group slow diff --git a/tests/test_framework/phpbb_database_connection_helper.php b/tests/test_framework/phpbb_database_connection_helper.php index fbb85784f8..5eba2e7a2e 100644 --- a/tests/test_framework/phpbb_database_connection_helper.php +++ b/tests/test_framework/phpbb_database_connection_helper.php @@ -14,7 +14,7 @@ * * This is used in the custom PHPUnit ODBC driver */ -class phpbb_database_connection_ODBC_PDO_wrapper extends PDO +class phpbb_database_connection_odbc_pdo_wrapper extends PDO { // Name of the driver being used (i.e. mssql, firebird) public $driver = ''; diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 3c4a112d0d..8e214121f3 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -97,13 +97,13 @@ class phpbb_database_test_connection_manager { case 'mssql': case 'mssql_odbc': - $this->pdo = new phpbb_database_connection_ODBC_PDO_wrapper('mssql', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']); + $this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('mssql', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']); break; case 'firebird': if (!empty($this->config['custom_dsn'])) { - $this->pdo = new phpbb_database_connection_ODBC_PDO_wrapper('firebird', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']); + $this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('firebird', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']); break; } // Fall through if they're using the firebird PDO driver and not the generic ODBC driver -- cgit v1.2.1 From 3cdcd44c4b056211f3e3291a4e58beddbb81e25d Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Fri, 13 Apr 2012 01:40:55 -0500 Subject: [ticket/10678] Rename helper class file PHPBB3-10678 --- .../phpbb_database_connection_helper.php | 32 ---------------------- .../phpbb_database_connection_odbc_pdo_wrapper.php | 32 ++++++++++++++++++++++ .../phpbb_database_test_connection_manager.php | 2 +- 3 files changed, 33 insertions(+), 33 deletions(-) delete mode 100644 tests/test_framework/phpbb_database_connection_helper.php create mode 100644 tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php (limited to 'tests') diff --git a/tests/test_framework/phpbb_database_connection_helper.php b/tests/test_framework/phpbb_database_connection_helper.php deleted file mode 100644 index 5eba2e7a2e..0000000000 --- a/tests/test_framework/phpbb_database_connection_helper.php +++ /dev/null @@ -1,32 +0,0 @@ -driver = $dbms; - $this->version = (double)$version; - - parent::__construct($dsn, $user, $pass); - } -} diff --git a/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php b/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php new file mode 100644 index 0000000000..5eba2e7a2e --- /dev/null +++ b/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php @@ -0,0 +1,32 @@ +driver = $dbms; + $this->version = (double)$version; + + parent::__construct($dsn, $user, $pass); + } +} diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 8e214121f3..0335c0de36 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -8,7 +8,7 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_install.php'; -require_once dirname(__FILE__) . '/phpbb_database_connection_helper.php'; +require_once dirname(__FILE__) . '/phpbb_database_connection_odbc_pdo_wrapper.php'; class phpbb_database_test_connection_manager { -- cgit v1.2.1 From 711d09633a17ef40e9efe67433f2285fa11f0608 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Tue, 8 May 2012 04:34:19 -0500 Subject: [ticket/10678] Move config changes to new location PHPBB3-10678 --- tests/test_framework/phpbb_test_case_helpers.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index b46c36efaa..3622fb1b1a 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -69,6 +69,7 @@ class phpbb_test_case_helpers 'dbname' => $dbname, 'dbuser' => $dbuser, 'dbpasswd' => $dbpasswd, + 'custom_dsn' => isset($custom_dsn) ? $custom_dsn : '', )); if (isset($phpbb_functional_url)) @@ -85,7 +86,8 @@ class phpbb_test_case_helpers 'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '', 'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '', 'dbuser' => isset($_SERVER['PHPBB_TEST_DBUSER']) ? $_SERVER['PHPBB_TEST_DBUSER'] : '', - 'dbpasswd' => isset($_SERVER['PHPBB_TEST_DBPASSWD']) ? $_SERVER['PHPBB_TEST_DBPASSWD'] : '' + 'dbpasswd' => isset($_SERVER['PHPBB_TEST_DBPASSWD']) ? $_SERVER['PHPBB_TEST_DBPASSWD'] : '', + 'custom_dsn' => isset($_SERVER['PHPBB_TEST_CUSTOM_DSN']) ? $_SERVER['PHPBB_TEST_CUSTOM_DSN'] : '', )); } -- cgit v1.2.1 From 1496a4198a930e3f9412f6beb6c0307ddeeb6dda Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Tue, 8 May 2012 04:35:47 -0500 Subject: [ticket/10678] Add port handling for MSSQL tests PHPBB3-10678 --- tests/test_framework/phpbb_database_test_connection_manager.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 0335c0de36..2e93b6799c 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -63,6 +63,13 @@ class phpbb_database_test_connection_manager // e.g. Driver={SQL Server Native Client 10.0};Server=(local)\SQLExpress; $dsn .= $this->config['dbhost']; + // Primarily for MSSQL Native/Azure as ODBC needs it in $dbhost, attached to the Server param + if ($this->config['dbport']) + { + $port_delimiter = (defined('PHP_OS') && substr(PHP_OS, 0, 3) === 'WIN') ? ',' : ':'; + $dsn .= $port_delimiter . $this->config['dbport']; + } + if ($use_db) { $dsn .= ';Database=' . $this->config['dbname']; -- cgit v1.2.1 From 9a38a034e56fc6e30207f1fee385f0b18de0dcc2 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 10 May 2012 03:23:48 -0400 Subject: [ticket/10882] Add test for an invalid template tag. PHPBB3-10882 --- tests/template/invalid_constructs_test.php | 43 ++++++++++++++++++++++ .../templates/invalid/output/unknown_tag.html | 1 + tests/template/templates/invalid/unknown_tag.html | 1 + 3 files changed, 45 insertions(+) create mode 100644 tests/template/invalid_constructs_test.php create mode 100644 tests/template/templates/invalid/output/unknown_tag.html create mode 100644 tests/template/templates/invalid/unknown_tag.html (limited to 'tests') diff --git a/tests/template/invalid_constructs_test.php b/tests/template/invalid_constructs_test.php new file mode 100644 index 0000000000..08fb5d4289 --- /dev/null +++ b/tests/template/invalid_constructs_test.php @@ -0,0 +1,43 @@ +template->cachepath . str_replace('/', '.', $file) . '.php'; + + $this->assertFileNotExists($cache_file); + + $expected = file_get_contents(dirname(__FILE__) . '/templates/' . $expected); + // apparently the template engine does not put + // the trailing newline into compiled templates + $expected = trim($expected); + $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); + } +} diff --git a/tests/template/templates/invalid/output/unknown_tag.html b/tests/template/templates/invalid/output/unknown_tag.html new file mode 100644 index 0000000000..1489e5e31a --- /dev/null +++ b/tests/template/templates/invalid/output/unknown_tag.html @@ -0,0 +1 @@ + diff --git a/tests/template/templates/invalid/unknown_tag.html b/tests/template/templates/invalid/unknown_tag.html new file mode 100644 index 0000000000..1489e5e31a --- /dev/null +++ b/tests/template/templates/invalid/unknown_tag.html @@ -0,0 +1 @@ + -- cgit v1.2.1 From 720d07c9b3942a103ceedc1996fb11e13c1bc2f0 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 10 May 2012 03:28:54 -0400 Subject: [ticket/10882] Add test for an ENDIF without IF. PHPBB3-10882 --- tests/template/invalid_constructs_test.php | 12 ++++++++++++ tests/template/templates/invalid/endif_without_if.html | 1 + .../template/templates/invalid/output/endif_without_if.html | 1 + 3 files changed, 14 insertions(+) create mode 100644 tests/template/templates/invalid/endif_without_if.html create mode 100644 tests/template/templates/invalid/output/endif_without_if.html (limited to 'tests') diff --git a/tests/template/invalid_constructs_test.php b/tests/template/invalid_constructs_test.php index 08fb5d4289..8d54df5014 100644 --- a/tests/template/invalid_constructs_test.php +++ b/tests/template/invalid_constructs_test.php @@ -22,6 +22,18 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), 'invalid/output/unknown_tag.html', ), + /* + * Produces a parse error which is fatal, therefore + * destroying the test suite. + array( + 'ENDIF without IF', + 'invalid/endif_without_if.html', + array(), + array(), + array(), + 'invalid/output/endif_without_if.html', + ), + */ ); } diff --git a/tests/template/templates/invalid/endif_without_if.html b/tests/template/templates/invalid/endif_without_if.html new file mode 100644 index 0000000000..e371ffd150 --- /dev/null +++ b/tests/template/templates/invalid/endif_without_if.html @@ -0,0 +1 @@ + diff --git a/tests/template/templates/invalid/output/endif_without_if.html b/tests/template/templates/invalid/output/endif_without_if.html new file mode 100644 index 0000000000..5f2239c964 --- /dev/null +++ b/tests/template/templates/invalid/output/endif_without_if.html @@ -0,0 +1 @@ +Parse error (fatal, destroys php runtime). -- cgit v1.2.1 From 56b2b87423c9afd62312fd36b5c2f6fff2d1d8a7 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 10 May 2012 03:36:58 -0400 Subject: [ticket/10882] Add a test for including a nonexistent file. PHPBB3-10882 --- tests/template/invalid_constructs_test.php | 32 ++++++++++++++++++++++ .../invalid/include_nonexistent_file.html | 1 + .../invalid/output/include_nonexistent_file.html | 1 + 3 files changed, 34 insertions(+) create mode 100644 tests/template/templates/invalid/include_nonexistent_file.html create mode 100644 tests/template/templates/invalid/output/include_nonexistent_file.html (limited to 'tests') diff --git a/tests/template/invalid_constructs_test.php b/tests/template/invalid_constructs_test.php index 8d54df5014..2430b5b9b1 100644 --- a/tests/template/invalid_constructs_test.php +++ b/tests/template/invalid_constructs_test.php @@ -37,6 +37,21 @@ class phpbb_template_template_test extends phpbb_template_template_test_case ); } + public function template_data_error() + { + return array( + array( + 'Include a nonexistent file', + 'invalid/include_nonexistent_file.html', + array(), + array(), + array(), + E_USER_ERROR, + 'invalid/output/include_nonexistent_file.html', + ), + ); + } + /** * @dataProvider template_data */ @@ -52,4 +67,21 @@ class phpbb_template_template_test extends phpbb_template_template_test_case $expected = trim($expected); $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); } + + /** + * @dataProvider template_data_error + */ + public function test_template_error($description, $file, $vars, $block_vars, $destroy, $error, $expected) + { + $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php'; + + $this->assertFileNotExists($cache_file); + + $expected = file_get_contents(dirname(__FILE__) . '/templates/' . $expected); + // apparently the template engine does not put + // the trailing newline into compiled templates + $expected = trim($expected); + $this->setExpectedTriggerError($error, $expected); + $this->run_template($file, $vars, $block_vars, $destroy, '', $cache_file); + } } diff --git a/tests/template/templates/invalid/include_nonexistent_file.html b/tests/template/templates/invalid/include_nonexistent_file.html new file mode 100644 index 0000000000..617d2fdaaa --- /dev/null +++ b/tests/template/templates/invalid/include_nonexistent_file.html @@ -0,0 +1 @@ + diff --git a/tests/template/templates/invalid/output/include_nonexistent_file.html b/tests/template/templates/invalid/output/include_nonexistent_file.html new file mode 100644 index 0000000000..8a118d2713 --- /dev/null +++ b/tests/template/templates/invalid/output/include_nonexistent_file.html @@ -0,0 +1 @@ +style resource locator: File for handle nonexistent.html does not exist. Could not find: -- cgit v1.2.1 From 29b36b214a809b6ae49f941a4e3965ffba2b8741 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Sun, 13 May 2012 16:56:07 -0500 Subject: [ticket/10678] Typo and formatting PHPBB3-10678 --- .../phpbb_database_connection_odbc_pdo_wrapper.php | 2 +- tests/test_framework/phpbb_database_test_case.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php b/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php index 5eba2e7a2e..cb5956be9f 100644 --- a/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php +++ b/tests/test_framework/phpbb_database_connection_odbc_pdo_wrapper.php @@ -25,7 +25,7 @@ class phpbb_database_connection_odbc_pdo_wrapper extends PDO function __construct($dbms, $version, $dsn, $user, $pass) { $this->driver = $dbms; - $this->version = (double)$version; + $this->version = (double) $version; parent::__construct($dsn, $user, $pass); } diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 53c3702aa6..bb86df0ef0 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -39,11 +39,11 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $xml_data = preg_replace_callback('/(?:(
))/', 'phpbb_database_test_case::to_upper', $xml_data); $xml_data = preg_replace_callback('/(?:())([a-z_]+)(?:(<\/column>))/', 'phpbb_database_test_case::to_upper', $xml_data); - $temp = tmpfile(); - fwrite($temp, $xml_data); - fseek($temp, 0); + $new_fixture = tmpfile(); + fwrite($new_fixture, $xml_data); + fseek($new_fixture, 0); - $meta_data = stream_get_meta_data($temp); + $meta_data = stream_get_meta_data($new_fixture); $path = $meta_data['uri']; } @@ -131,7 +131,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test /** * Converts a match in the middle of a string to uppercase. - * This is necessary for tranforming the fixture information for Firebird tests + * This is necessary for transforming the fixture information for Firebird tests * * @param $matches The array of matches from a regular expression * -- cgit v1.2.1 From 9fa7ab62ad45abf3a5035cc792748893d6cd8a4d Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 21 May 2012 23:02:12 -0400 Subject: [ticket/10828] Connect to postgres database by default. When not connecting to a specific database, connect to postgres database which specifically exists as a default database to connect to. PHPBB3-10828 --- .../phpbb_database_test_connection_manager.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index c734c90a1a..ae21be6c34 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -80,6 +80,21 @@ class phpbb_database_test_connection_manager { $dsn .= ';dbname=' . $this->config['dbname']; } + else if ($this->dbms['PDO'] == 'pgsql') + { + // Postgres always connects to a + // database. If the database is not + // specified here, but the username + // is specified, then connection + // will be to the database named + // as the username. + // + // For greater compatibility, connect + // instead to postgres database which + // should always exist: + // http://www.postgresql.org/docs/9.0/static/manage-ag-templatedbs.html + $dsn .= ';dbname=postgres'; + } break; } -- cgit v1.2.1 From afd6f86892fbbbe06aa0b1295dba361fab29fd5f Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 11 Jun 2012 13:22:11 +0200 Subject: [ticket/10931] Unit tests for phpbb_php_ini class. PHPBB3-10931 --- tests/mock/phpbb_php_ini.php | 16 ++++++++++ tests/wrapper/phpbb_php_ini_test.php | 58 ++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 tests/mock/phpbb_php_ini.php create mode 100644 tests/wrapper/phpbb_php_ini_test.php (limited to 'tests') diff --git a/tests/mock/phpbb_php_ini.php b/tests/mock/phpbb_php_ini.php new file mode 100644 index 0000000000..249c1b014a --- /dev/null +++ b/tests/mock/phpbb_php_ini.php @@ -0,0 +1,16 @@ +php_ini = new phpbb_mock_phpbb_php_ini; + } + + public function test_get_string() + { + $this->assertEquals('phpbb', $this->php_ini->get_string(' phpbb ')); + } + + public function test_get_bool() + { + $this->assertEquals(true, $this->php_ini->get_bool('ON')); + $this->assertEquals(true, $this->php_ini->get_bool('on')); + $this->assertEquals(true, $this->php_ini->get_bool('1')); + + $this->assertEquals(false, $this->php_ini->get_bool('OFF')); + $this->assertEquals(false, $this->php_ini->get_bool('off')); + $this->assertEquals(false, $this->php_ini->get_bool('0')); + $this->assertEquals(false, $this->php_ini->get_bool('')); + } + + public function test_get_int() + { + $this->assertEquals(1234, $this->php_ini->get_int('1234')); + $this->assertEquals(false, $this->php_ini->get_int('phpBB')); + } + + public function test_get_float() + { + $this->assertEquals(1234.0, $this->php_ini->get_float('1234')); + $this->assertEquals(false, $this->php_ini->get_float('phpBB')); + } + + public function test_get_bytes() + { + $this->assertEquals(false, $this->php_ini->get_bytes('phpBB')); + $this->assertEquals(false, $this->php_ini->get_bytes('M')); + $this->assertEquals(32 * pow(2, 20), $this->php_ini->get_bytes('32M')); + $this->assertEquals(8 * pow(2, 30), $this->php_ini->get_bytes('8G')); + $this->assertEquals(1234, $this->php_ini->get_bytes('1234')); + } +} -- cgit v1.2.1 From 5086366662d78d79bb6daf4b132709d9273c2f8c Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 11 Jun 2012 14:18:21 +0200 Subject: [ticket/10931] Make it clear that we are mocking the ini_get() function. PHPBB3-10931 --- tests/mock/phpbb_php_ini.php | 16 ---------------- tests/wrapper/phpbb_php_ini_fake.php | 16 ++++++++++++++++ tests/wrapper/phpbb_php_ini_test.php | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) delete mode 100644 tests/mock/phpbb_php_ini.php create mode 100644 tests/wrapper/phpbb_php_ini_fake.php (limited to 'tests') diff --git a/tests/mock/phpbb_php_ini.php b/tests/mock/phpbb_php_ini.php deleted file mode 100644 index 249c1b014a..0000000000 --- a/tests/mock/phpbb_php_ini.php +++ /dev/null @@ -1,16 +0,0 @@ -php_ini = new phpbb_mock_phpbb_php_ini; + $this->php_ini = new phpbb_php_ini_fake; } public function test_get_string() -- cgit v1.2.1 From 80dfa53ee3f04dfdba11efe9eb3f49d739bb602b Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 11 Jun 2012 14:24:30 +0200 Subject: [ticket/10931] Correctly use GNU GPL version 2. PHPBB3-10931 --- tests/wrapper/phpbb_php_ini_fake.php | 2 +- tests/wrapper/phpbb_php_ini_test.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/wrapper/phpbb_php_ini_fake.php b/tests/wrapper/phpbb_php_ini_fake.php index 14ec77c644..49bc5936e5 100644 --- a/tests/wrapper/phpbb_php_ini_fake.php +++ b/tests/wrapper/phpbb_php_ini_fake.php @@ -3,7 +3,7 @@ * * @package testing * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/tests/wrapper/phpbb_php_ini_test.php b/tests/wrapper/phpbb_php_ini_test.php index 5494f1864d..cdfee802f2 100644 --- a/tests/wrapper/phpbb_php_ini_test.php +++ b/tests/wrapper/phpbb_php_ini_test.php @@ -3,7 +3,7 @@ * * @package testing * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -- cgit v1.2.1 From fb279c9677641db5efa38f24c51db93df004cb46 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 11 Jun 2012 14:31:09 +0200 Subject: [ticket/10931] Also test lower case units in test_get_bytes(). PHPBB3-10931 --- tests/wrapper/phpbb_php_ini_test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/wrapper/phpbb_php_ini_test.php b/tests/wrapper/phpbb_php_ini_test.php index cdfee802f2..cbb05e98e9 100644 --- a/tests/wrapper/phpbb_php_ini_test.php +++ b/tests/wrapper/phpbb_php_ini_test.php @@ -50,8 +50,9 @@ class phpbb_wrapper_phpbb_php_ini_test extends phpbb_test_case public function test_get_bytes() { $this->assertEquals(false, $this->php_ini->get_bytes('phpBB')); + $this->assertEquals(false, $this->php_ini->get_bytes('k')); $this->assertEquals(false, $this->php_ini->get_bytes('M')); - $this->assertEquals(32 * pow(2, 20), $this->php_ini->get_bytes('32M')); + $this->assertEquals(32 * pow(2, 20), $this->php_ini->get_bytes('32m')); $this->assertEquals(8 * pow(2, 30), $this->php_ini->get_bytes('8G')); $this->assertEquals(1234, $this->php_ini->get_bytes('1234')); } -- cgit v1.2.1 From 3872abd824c9371af6cbb45e6e9bbfcb31094f98 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 11 Jun 2012 14:35:18 +0200 Subject: [ticket/10931] Also test for negative values. PHPBB3-10931 --- tests/wrapper/phpbb_php_ini_test.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests') diff --git a/tests/wrapper/phpbb_php_ini_test.php b/tests/wrapper/phpbb_php_ini_test.php index cbb05e98e9..84e2b5e92e 100644 --- a/tests/wrapper/phpbb_php_ini_test.php +++ b/tests/wrapper/phpbb_php_ini_test.php @@ -38,12 +38,14 @@ class phpbb_wrapper_phpbb_php_ini_test extends phpbb_test_case public function test_get_int() { $this->assertEquals(1234, $this->php_ini->get_int('1234')); + $this->assertEquals(-12345, $this->php_ini->get_int('-12345')); $this->assertEquals(false, $this->php_ini->get_int('phpBB')); } public function test_get_float() { $this->assertEquals(1234.0, $this->php_ini->get_float('1234')); + $this->assertEquals(-12345.0, $this->php_ini->get_float('-12345')); $this->assertEquals(false, $this->php_ini->get_float('phpBB')); } @@ -51,9 +53,14 @@ class phpbb_wrapper_phpbb_php_ini_test extends phpbb_test_case { $this->assertEquals(false, $this->php_ini->get_bytes('phpBB')); $this->assertEquals(false, $this->php_ini->get_bytes('k')); + $this->assertEquals(false, $this->php_ini->get_bytes('-k')); $this->assertEquals(false, $this->php_ini->get_bytes('M')); + $this->assertEquals(false, $this->php_ini->get_bytes('-M')); $this->assertEquals(32 * pow(2, 20), $this->php_ini->get_bytes('32m')); + $this->assertEquals(- 32 * pow(2, 20), $this->php_ini->get_bytes('-32m')); $this->assertEquals(8 * pow(2, 30), $this->php_ini->get_bytes('8G')); + $this->assertEquals(- 8 * pow(2, 30), $this->php_ini->get_bytes('-8G')); $this->assertEquals(1234, $this->php_ini->get_bytes('1234')); + $this->assertEquals(-12345, $this->php_ini->get_bytes('-12345')); } } -- cgit v1.2.1 From 44287e57bf9536bd91933347ad64f289ef2a0391 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 11 Jun 2012 14:43:50 +0200 Subject: [ticket/10931] Use strict assertSame() instead of assertEquals(). PHPBB3-10931 --- tests/wrapper/phpbb_php_ini_test.php | 38 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/tests/wrapper/phpbb_php_ini_test.php b/tests/wrapper/phpbb_php_ini_test.php index 84e2b5e92e..5c312300d3 100644 --- a/tests/wrapper/phpbb_php_ini_test.php +++ b/tests/wrapper/phpbb_php_ini_test.php @@ -20,42 +20,42 @@ class phpbb_wrapper_phpbb_php_ini_test extends phpbb_test_case public function test_get_string() { - $this->assertEquals('phpbb', $this->php_ini->get_string(' phpbb ')); + $this->assertSame('phpbb', $this->php_ini->get_string(' phpbb ')); } public function test_get_bool() { - $this->assertEquals(true, $this->php_ini->get_bool('ON')); - $this->assertEquals(true, $this->php_ini->get_bool('on')); - $this->assertEquals(true, $this->php_ini->get_bool('1')); + $this->assertSame(true, $this->php_ini->get_bool('ON')); + $this->assertSame(true, $this->php_ini->get_bool('on')); + $this->assertSame(true, $this->php_ini->get_bool('1')); - $this->assertEquals(false, $this->php_ini->get_bool('OFF')); - $this->assertEquals(false, $this->php_ini->get_bool('off')); - $this->assertEquals(false, $this->php_ini->get_bool('0')); - $this->assertEquals(false, $this->php_ini->get_bool('')); + $this->assertSame(false, $this->php_ini->get_bool('OFF')); + $this->assertSame(false, $this->php_ini->get_bool('off')); + $this->assertSame(false, $this->php_ini->get_bool('0')); + $this->assertSame(false, $this->php_ini->get_bool('')); } public function test_get_int() { - $this->assertEquals(1234, $this->php_ini->get_int('1234')); - $this->assertEquals(-12345, $this->php_ini->get_int('-12345')); - $this->assertEquals(false, $this->php_ini->get_int('phpBB')); + $this->assertSame(1234, $this->php_ini->get_int('1234')); + $this->assertSame(-12345, $this->php_ini->get_int('-12345')); + $this->assertSame(false, $this->php_ini->get_int('phpBB')); } public function test_get_float() { - $this->assertEquals(1234.0, $this->php_ini->get_float('1234')); - $this->assertEquals(-12345.0, $this->php_ini->get_float('-12345')); - $this->assertEquals(false, $this->php_ini->get_float('phpBB')); + $this->assertSame(1234.0, $this->php_ini->get_float('1234')); + $this->assertSame(-12345.0, $this->php_ini->get_float('-12345')); + $this->assertSame(false, $this->php_ini->get_float('phpBB')); } public function test_get_bytes() { - $this->assertEquals(false, $this->php_ini->get_bytes('phpBB')); - $this->assertEquals(false, $this->php_ini->get_bytes('k')); - $this->assertEquals(false, $this->php_ini->get_bytes('-k')); - $this->assertEquals(false, $this->php_ini->get_bytes('M')); - $this->assertEquals(false, $this->php_ini->get_bytes('-M')); + $this->assertSame(false, $this->php_ini->get_bytes('phpBB')); + $this->assertSame(false, $this->php_ini->get_bytes('k')); + $this->assertSame(false, $this->php_ini->get_bytes('-k')); + $this->assertSame(false, $this->php_ini->get_bytes('M')); + $this->assertSame(false, $this->php_ini->get_bytes('-M')); $this->assertEquals(32 * pow(2, 20), $this->php_ini->get_bytes('32m')); $this->assertEquals(- 32 * pow(2, 20), $this->php_ini->get_bytes('-32m')); $this->assertEquals(8 * pow(2, 30), $this->php_ini->get_bytes('8G')); -- cgit v1.2.1 From 09fb9a9efe048cef102471d1ce79cdeff932776a Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 11 Jun 2012 15:15:08 +0200 Subject: [ticket/10931] Make sure get_bytes() always returns either an int or a float. PHPBB3-10931 --- tests/wrapper/phpbb_php_ini_test.php | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/wrapper/phpbb_php_ini_test.php b/tests/wrapper/phpbb_php_ini_test.php index 5c312300d3..4d8e583eb8 100644 --- a/tests/wrapper/phpbb_php_ini_test.php +++ b/tests/wrapper/phpbb_php_ini_test.php @@ -49,18 +49,35 @@ class phpbb_wrapper_phpbb_php_ini_test extends phpbb_test_case $this->assertSame(false, $this->php_ini->get_float('phpBB')); } - public function test_get_bytes() + public function test_get_bytes_invalid() { $this->assertSame(false, $this->php_ini->get_bytes('phpBB')); $this->assertSame(false, $this->php_ini->get_bytes('k')); $this->assertSame(false, $this->php_ini->get_bytes('-k')); $this->assertSame(false, $this->php_ini->get_bytes('M')); $this->assertSame(false, $this->php_ini->get_bytes('-M')); - $this->assertEquals(32 * pow(2, 20), $this->php_ini->get_bytes('32m')); - $this->assertEquals(- 32 * pow(2, 20), $this->php_ini->get_bytes('-32m')); - $this->assertEquals(8 * pow(2, 30), $this->php_ini->get_bytes('8G')); - $this->assertEquals(- 8 * pow(2, 30), $this->php_ini->get_bytes('-8G')); - $this->assertEquals(1234, $this->php_ini->get_bytes('1234')); - $this->assertEquals(-12345, $this->php_ini->get_bytes('-12345')); + } + + /** + * @dataProvider get_bytes_data + */ + public function test_get_bytes($expected, $value) + { + $actual = $this->php_ini->get_bytes($value); + + $this->assertTrue(is_float($actual) || is_int($actual)); + $this->assertEquals($expected, $actual); + } + + static public function get_bytes_data() + { + return array( + array(32 * pow(2, 20), '32m'), + array(- 32 * pow(2, 20), '-32m'), + array(8 * pow(2, 30), '8G'), + array(- 8 * pow(2, 30), '-8G'), + array(1234, '1234'), + array(-12345, '-12345'), + ); } } -- cgit v1.2.1 From cbff02db4f84c83c62bdd1f7450b8afbf39a5270 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 11 Jun 2012 15:22:55 +0200 Subject: [ticket/10931] Make to_numeric function globally available. PHPBB3-10931 --- tests/wrapper/phpbb_php_ini_test.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/wrapper/phpbb_php_ini_test.php b/tests/wrapper/phpbb_php_ini_test.php index 4d8e583eb8..418448f102 100644 --- a/tests/wrapper/phpbb_php_ini_test.php +++ b/tests/wrapper/phpbb_php_ini_test.php @@ -8,6 +8,7 @@ */ require_once dirname(__FILE__) . '/phpbb_php_ini_fake.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; class phpbb_wrapper_phpbb_php_ini_test extends phpbb_test_case { -- cgit v1.2.1 From 72212077ebecee639c49c473646a38340908d058 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 11 Jun 2012 15:31:25 +0200 Subject: [ticket/10931] Also test get_bytes() and get_string() with false. PHPBB3-10931 --- tests/wrapper/phpbb_php_ini_test.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/wrapper/phpbb_php_ini_test.php b/tests/wrapper/phpbb_php_ini_test.php index 418448f102..8e08d5c204 100644 --- a/tests/wrapper/phpbb_php_ini_test.php +++ b/tests/wrapper/phpbb_php_ini_test.php @@ -21,6 +21,7 @@ class phpbb_wrapper_phpbb_php_ini_test extends phpbb_test_case public function test_get_string() { + $this->assertSame(false, $this->php_ini->get_string(false)); $this->assertSame('phpbb', $this->php_ini->get_string(' phpbb ')); } @@ -52,6 +53,7 @@ class phpbb_wrapper_phpbb_php_ini_test extends phpbb_test_case public function test_get_bytes_invalid() { + $this->assertSame(false, $this->php_ini->get_bytes(false)); $this->assertSame(false, $this->php_ini->get_bytes('phpBB')); $this->assertSame(false, $this->php_ini->get_bytes('k')); $this->assertSame(false, $this->php_ini->get_bytes('-k')); -- cgit v1.2.1 From 241033ae88fdaa4aa45da0ee70b94f636e6d0360 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 11 Jun 2012 18:50:05 -0400 Subject: [ticket/10882] Fix test name - oops. PHPBB3-10882 --- tests/template/invalid_constructs_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/template/invalid_constructs_test.php b/tests/template/invalid_constructs_test.php index 2430b5b9b1..19d192b8b6 100644 --- a/tests/template/invalid_constructs_test.php +++ b/tests/template/invalid_constructs_test.php @@ -9,7 +9,7 @@ require_once dirname(__FILE__) . '/template_test_case.php'; -class phpbb_template_template_test extends phpbb_template_template_test_case +class phpbb_template_invalid_constructs_test extends phpbb_template_template_test_case { public function template_data() { -- cgit v1.2.1 From dd0da6fffb3358937ebfdb3ff347089d97e64a1a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 01:50:42 +0200 Subject: [ticket/10942] Add unit tests for sql_conditional PHPBB3-10942 --- tests/dbal/conditional_test.php | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/dbal/conditional_test.php (limited to 'tests') diff --git a/tests/dbal/conditional_test.php b/tests/dbal/conditional_test.php new file mode 100644 index 0000000000..3e01de05f6 --- /dev/null +++ b/tests/dbal/conditional_test.php @@ -0,0 +1,64 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + } + + public function test_conditional_string() + { + $db = $this->new_dbal(); + + $sql = 'SELECT config_name, ' . $db->sql_conditional('is_dynamic = 1', "'" . $db->sql_escape('true') . "'", "'" . $db->sql_escape('false') . "'") . ' AS string + FROM phpbb_config'; + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array( + 'config_name' => 'config1', + 'string' => 'false', + ), + array( + 'config_name' => 'config2', + 'string' => 'true', + ), + ), + $db->sql_fetchrowset($result) + ); + } + + public function test_conditional_statement() + { + $db = $this->new_dbal(); + + $sql = 'SELECT config_name, ' . $db->sql_conditional('is_dynamic = 1', 'is_dynamic', 'config_value') . ' AS string + FROM phpbb_config'; + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array( + 'config_name' => 'config1', + 'string' => 'foo', + ), + array( + 'config_name' => 'config2', + 'string' => '1', + ), + ), + $db->sql_fetchrowset($result) + ); + } +} -- cgit v1.2.1 From 8cea7b2a5173a69889d76b1e27469cf15e95cefc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 02:10:54 +0200 Subject: [ticket/10942] Add unit tests for sql_concatenate PHPBB3-10942 --- tests/dbal/concatenate_test.php | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/dbal/concatenate_test.php (limited to 'tests') diff --git a/tests/dbal/concatenate_test.php b/tests/dbal/concatenate_test.php new file mode 100644 index 0000000000..0891fa58a0 --- /dev/null +++ b/tests/dbal/concatenate_test.php @@ -0,0 +1,64 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + } + + public function test_concatenate_string() + { + $db = $this->new_dbal(); + + $sql = 'SELECT config_name, ' . $db->sql_concatenate('config_name', "'" . $db->sql_escape('append') . "'") . ' AS string + FROM phpbb_config'; + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array( + 'config_name' => 'config1', + 'string' => 'config1append', + ), + array( + 'config_name' => 'config2', + 'string' => 'config2append', + ), + ), + $db->sql_fetchrowset($result) + ); + } + + public function test_concatenate_statement() + { + $db = $this->new_dbal(); + + $sql = 'SELECT config_name, ' . $db->sql_concatenate('config_name', 'config_value') . ' AS string + FROM phpbb_config'; + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array( + 'config_name' => 'config1', + 'string' => 'config1foo', + ), + array( + 'config_name' => 'config2', + 'string' => 'config2bar', + ), + ), + $db->sql_fetchrowset($result) + ); + } +} -- cgit v1.2.1 From 4fbbbfcebb6f8ed9867cb61623767a2f4c191ed6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 02:12:48 +0200 Subject: [ticket/10942] Fix function name on order_lower_test.php PHPBB3-10942 --- tests/dbal/order_lower_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/dbal/order_lower_test.php b/tests/dbal/order_lower_test.php index e16c0c20ee..84d454742f 100644 --- a/tests/dbal/order_lower_test.php +++ b/tests/dbal/order_lower_test.php @@ -14,7 +14,7 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/styles.xml'); } - public function test_cross_join() + public function test_order_lower() { $db = $this->new_dbal(); -- cgit v1.2.1 From 089e5f5c79965058a5288590a3a34d94f3bcb833 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 12:57:08 +0200 Subject: [ticket/10942] Rename method sql_conditional() to sql_case() PHPBB3-10942 --- tests/dbal/case_test.php | 64 +++++++++++++++++++++++++++++++++++++++++ tests/dbal/conditional_test.php | 64 ----------------------------------------- 2 files changed, 64 insertions(+), 64 deletions(-) create mode 100644 tests/dbal/case_test.php delete mode 100644 tests/dbal/conditional_test.php (limited to 'tests') diff --git a/tests/dbal/case_test.php b/tests/dbal/case_test.php new file mode 100644 index 0000000000..7e966c0ec1 --- /dev/null +++ b/tests/dbal/case_test.php @@ -0,0 +1,64 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + } + + public function test_case_string() + { + $db = $this->new_dbal(); + + $sql = 'SELECT config_name, ' . $db->sql_case('is_dynamic = 1', "'" . $db->sql_escape('true') . "'", "'" . $db->sql_escape('false') . "'") . ' AS string + FROM phpbb_config'; + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array( + 'config_name' => 'config1', + 'string' => 'false', + ), + array( + 'config_name' => 'config2', + 'string' => 'true', + ), + ), + $db->sql_fetchrowset($result) + ); + } + + public function test_case_statement() + { + $db = $this->new_dbal(); + + $sql = 'SELECT config_name, ' . $db->sql_case('is_dynamic = 1', 'is_dynamic', 'config_value') . ' AS string + FROM phpbb_config'; + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array( + 'config_name' => 'config1', + 'string' => 'foo', + ), + array( + 'config_name' => 'config2', + 'string' => '1', + ), + ), + $db->sql_fetchrowset($result) + ); + } +} diff --git a/tests/dbal/conditional_test.php b/tests/dbal/conditional_test.php deleted file mode 100644 index 3e01de05f6..0000000000 --- a/tests/dbal/conditional_test.php +++ /dev/null @@ -1,64 +0,0 @@ -createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); - } - - public function test_conditional_string() - { - $db = $this->new_dbal(); - - $sql = 'SELECT config_name, ' . $db->sql_conditional('is_dynamic = 1', "'" . $db->sql_escape('true') . "'", "'" . $db->sql_escape('false') . "'") . ' AS string - FROM phpbb_config'; - $result = $db->sql_query($sql); - - $db->sql_return_on_error(false); - - $this->assertEquals(array( - array( - 'config_name' => 'config1', - 'string' => 'false', - ), - array( - 'config_name' => 'config2', - 'string' => 'true', - ), - ), - $db->sql_fetchrowset($result) - ); - } - - public function test_conditional_statement() - { - $db = $this->new_dbal(); - - $sql = 'SELECT config_name, ' . $db->sql_conditional('is_dynamic = 1', 'is_dynamic', 'config_value') . ' AS string - FROM phpbb_config'; - $result = $db->sql_query($sql); - - $db->sql_return_on_error(false); - - $this->assertEquals(array( - array( - 'config_name' => 'config1', - 'string' => 'foo', - ), - array( - 'config_name' => 'config2', - 'string' => '1', - ), - ), - $db->sql_fetchrowset($result) - ); - } -} -- cgit v1.2.1 From 0fd02035d8dd12db4a793af5be564911fca4f900 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 30 Jun 2012 13:00:41 +0200 Subject: [ticket/10942] Make unit tests for sql_case simpler PHPBB3-10942 --- tests/dbal/case_test.php | 50 ++++++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 31 deletions(-) (limited to 'tests') diff --git a/tests/dbal/case_test.php b/tests/dbal/case_test.php index 7e966c0ec1..684f2c26a9 100644 --- a/tests/dbal/case_test.php +++ b/tests/dbal/case_test.php @@ -18,47 +18,35 @@ class phpbb_dbal_case_test extends phpbb_database_test_case { $db = $this->new_dbal(); - $sql = 'SELECT config_name, ' . $db->sql_case('is_dynamic = 1', "'" . $db->sql_escape('true') . "'", "'" . $db->sql_escape('false') . "'") . ' AS string + $sql = 'SELECT ' . $db->sql_case('1 = 1', '1', '0') . ' AS bool FROM phpbb_config'; - $result = $db->sql_query($sql); + $result = $db->sql_query_limit($sql, 1); - $db->sql_return_on_error(false); + $this->assertEquals(true, (bool) $db->sql_fetchfield('bool')); - $this->assertEquals(array( - array( - 'config_name' => 'config1', - 'string' => 'false', - ), - array( - 'config_name' => 'config2', - 'string' => 'true', - ), - ), - $db->sql_fetchrowset($result) - ); + $sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '0') . ' AS bool + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + + $this->assertEquals(false, (bool) $db->sql_fetchfield('bool')); } public function test_case_statement() { $db = $this->new_dbal(); - $sql = 'SELECT config_name, ' . $db->sql_case('is_dynamic = 1', 'is_dynamic', 'config_value') . ' AS string - FROM phpbb_config'; - $result = $db->sql_query($sql); + $sql = 'SELECT ' . $db->sql_case('is_dynamic = 1', 'is_dynamic', '0') . " AS bool + FROM phpbb_config + WHERE is_dynamic = 1"; + $result = $db->sql_query_limit($sql, 1); + + $this->assertEquals(true, (bool) $db->sql_fetchfield('bool')); - $db->sql_return_on_error(false); + $sql = 'SELECT ' . $db->sql_case('is_dynamic = 1', '1', 'is_dynamic') . " AS bool + FROM phpbb_config + WHERE is_dynamic = 0"; + $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(array( - array( - 'config_name' => 'config1', - 'string' => 'foo', - ), - array( - 'config_name' => 'config2', - 'string' => '1', - ), - ), - $db->sql_fetchrowset($result) - ); + $this->assertEquals(false, (bool) $db->sql_fetchfield('bool')); } } -- cgit v1.2.1 From ad9d6506594f90ac7c6cdf20a5718d28042059c9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 2 Jul 2012 11:10:58 +0200 Subject: [ticket/10942] Fix up unit tests for sql_case() PHPBB3-10942 --- tests/dbal/case_test.php | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/dbal/case_test.php b/tests/dbal/case_test.php index 684f2c26a9..5219defa06 100644 --- a/tests/dbal/case_test.php +++ b/tests/dbal/case_test.php @@ -14,39 +14,56 @@ class phpbb_dbal_case_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); } + public function test_case_int() + { + $db = $this->new_dbal(); + + $sql = 'SELECT ' . $db->sql_case('1 = 1', '1', '2') . ' AS num + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + + $this->assertEquals(1, (int) $db->sql_fetchfield('num')); + + $sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '2') . ' AS num + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + + $this->assertEquals(2, (int) $db->sql_fetchfield('num')); + } + public function test_case_string() { $db = $this->new_dbal(); - $sql = 'SELECT ' . $db->sql_case('1 = 1', '1', '0') . ' AS bool + $sql = 'SELECT ' . $db->sql_case('1 = 1', "'foo'", "'bar'") . ' AS string FROM phpbb_config'; $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(true, (bool) $db->sql_fetchfield('bool')); + $this->assertEquals('foo', $db->sql_fetchfield('string')); - $sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '0') . ' AS bool + $sql = 'SELECT ' . $db->sql_case('1 = 0', "'foo'", "'bar'") . ' AS string FROM phpbb_config'; $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(false, (bool) $db->sql_fetchfield('bool')); + $this->assertEquals('bar', $db->sql_fetchfield('string')); } - public function test_case_statement() + public function test_case_column() { $db = $this->new_dbal(); - $sql = 'SELECT ' . $db->sql_case('is_dynamic = 1', 'is_dynamic', '0') . " AS bool + $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS string FROM phpbb_config - WHERE is_dynamic = 1"; + WHERE config_name = 'config1'"; $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(true, (bool) $db->sql_fetchfield('bool')); + $this->assertEquals('config1', $db->sql_fetchfield('string')); - $sql = 'SELECT ' . $db->sql_case('is_dynamic = 1', '1', 'is_dynamic') . " AS bool + $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS string FROM phpbb_config - WHERE is_dynamic = 0"; + WHERE config_value = 'bar'"; $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(false, (bool) $db->sql_fetchfield('bool')); + $this->assertEquals('bar', $db->sql_fetchfield('string')); } } -- cgit v1.2.1 From 81d5327e4411a7044f1c90e002505cad309372d6 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 20 Jun 2012 13:56:11 +0200 Subject: [ticket/10937] Comment removal functions: Restore backward compatibility PHPBB3-10937 --- tests/test_framework/phpbb_database_test_connection_manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index c734c90a1a..dd022451b7 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -243,7 +243,7 @@ class phpbb_database_test_connection_manager $filename = $directory . $schema . '_schema.sql'; $queries = file_get_contents($filename); - $sql = remove_comments($queries); + $sql = phpbb_remove_comments($queries); $sql = split_sql_file($sql, $this->dbms['DELIM']); -- cgit v1.2.1 From 932428086ecfa9cdd2c27cb185da7e22420e602d Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 8 Jul 2012 22:33:27 +0200 Subject: [ticket/10973] Add autoloader for autoloading phpbb_mock_ in tests. PHPBB3-10973 --- tests/bootstrap.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/bootstrap.php b/tests/bootstrap.php index f103d8f15a..1017e0c72f 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -16,6 +16,8 @@ $table_prefix = 'phpbb_'; require_once $phpbb_root_path . 'includes/constants.php'; require_once $phpbb_root_path . 'includes/class_loader.' . $phpEx; +$phpbb_class_loader_mock = new phpbb_class_loader('phpbb_mock_', $phpbb_root_path . '../tests/mock/', ".php"); +$phpbb_class_loader_mock->register(); $phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path . 'ext/', ".php"); $phpbb_class_loader_ext->register(); $phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".php"); -- cgit v1.2.1 From cde5411e8aad0436ca709a46e109cd38e4c21a9e Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 8 Jul 2012 22:35:50 +0200 Subject: [ticket/10974] Rename tests/mock_user.php -> tests/mock/user.php PHPBB3-10974 --- tests/bbcode/url_bbcode_test.php | 2 +- tests/mock/user.php | 36 ++++++++++++++++++++++++++++++ tests/mock_user.php | 36 ------------------------------ tests/text_processing/censor_text_test.php | 2 +- 4 files changed, 38 insertions(+), 38 deletions(-) create mode 100644 tests/mock/user.php delete mode 100644 tests/mock_user.php (limited to 'tests') diff --git a/tests/bbcode/url_bbcode_test.php b/tests/bbcode/url_bbcode_test.php index 15bdfc434f..6b5afe5808 100644 --- a/tests/bbcode/url_bbcode_test.php +++ b/tests/bbcode/url_bbcode_test.php @@ -11,7 +11,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/message_parser.php'; -require_once dirname(__FILE__) . '/../mock_user.php'; +require_once dirname(__FILE__) . '/../mock/user.php'; class phpbb_url_bbcode_test extends phpbb_test_case { diff --git a/tests/mock/user.php b/tests/mock/user.php new file mode 100644 index 0000000000..ec14ce430e --- /dev/null +++ b/tests/mock/user.php @@ -0,0 +1,36 @@ + '/'); + + private $options = array(); + public function optionget($item) + { + if (!isset($this->options[$item])) + { + throw new Exception(sprintf("You didn't set the option '%s' on the mock user using optionset.", $item)); + } + + return $this->options[$item]; + } + + public function optionset($item, $value) + { + $this->options[$item] = $value; + } +} diff --git a/tests/mock_user.php b/tests/mock_user.php deleted file mode 100644 index ec14ce430e..0000000000 --- a/tests/mock_user.php +++ /dev/null @@ -1,36 +0,0 @@ - '/'); - - private $options = array(); - public function optionget($item) - { - if (!isset($this->options[$item])) - { - throw new Exception(sprintf("You didn't set the option '%s' on the mock user using optionset.", $item)); - } - - return $this->options[$item]; - } - - public function optionset($item, $value) - { - $this->options[$item] = $value; - } -} diff --git a/tests/text_processing/censor_text_test.php b/tests/text_processing/censor_text_test.php index 8fcdb7ef85..f0e13638a5 100644 --- a/tests/text_processing/censor_text_test.php +++ b/tests/text_processing/censor_text_test.php @@ -9,7 +9,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; -require_once dirname(__FILE__) . '/../mock_user.php'; +require_once dirname(__FILE__) . '/../mock/user.php'; require_once dirname(__FILE__) . '/../mock/cache.php'; class phpbb_text_processing_censor_text_test extends phpbb_test_case -- cgit v1.2.1 From d3bbde69c441a5d795a16e66c9cc7a9194f42218 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 8 Jul 2012 22:53:45 +0200 Subject: [ticket/10973] Drop all require_once for mocks. Use autoloading. PHPBB3-10973 --- tests/bbcode/url_bbcode_test.php | 2 -- tests/class_loader/class_loader_test.php | 2 -- tests/config/db_test.php | 2 -- tests/cron/manager_test.php | 1 - tests/cron/task_provider_test.php | 2 -- tests/download/http_byte_range_test.php | 1 - tests/extension/finder_test.php | 3 --- tests/extension/manager_test.php | 1 - tests/functions_acp/build_cfg_template_test.php | 1 - tests/functions_acp/build_select_test.php | 1 - tests/functions_acp/h_radio_test.php | 1 - tests/functions_acp/validate_config_vars_test.php | 1 - tests/functions_acp/validate_range_test.php | 1 - tests/security/base.php | 2 -- tests/session/continue_test.php | 1 - tests/session/init_test.php | 1 - tests/session/testable_factory.php | 3 --- tests/template/template_test_case.php | 1 - tests/text_processing/censor_text_test.php | 2 -- 19 files changed, 29 deletions(-) (limited to 'tests') diff --git a/tests/bbcode/url_bbcode_test.php b/tests/bbcode/url_bbcode_test.php index b944b6135d..d5df386714 100644 --- a/tests/bbcode/url_bbcode_test.php +++ b/tests/bbcode/url_bbcode_test.php @@ -11,8 +11,6 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/message_parser.php'; -require_once dirname(__FILE__) . '/../mock_user.php'; -require_once dirname(__FILE__) . '/../mock/request.php'; class phpbb_url_bbcode_test extends phpbb_test_case { diff --git a/tests/class_loader/class_loader_test.php b/tests/class_loader/class_loader_test.php index 80f0b38095..76af4dde37 100644 --- a/tests/class_loader/class_loader_test.php +++ b/tests/class_loader/class_loader_test.php @@ -7,8 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../mock/cache.php'; - class phpbb_class_loader_test extends PHPUnit_Framework_TestCase { public function setUp() diff --git a/tests/config/db_test.php b/tests/config/db_test.php index a9a53541a5..0b8f73d53a 100644 --- a/tests/config/db_test.php +++ b/tests/config/db_test.php @@ -7,8 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../mock/cache.php'; - class phpbb_config_db_test extends phpbb_database_test_case { private $cache; diff --git a/tests/cron/manager_test.php b/tests/cron/manager_test.php index f433fc9a9b..3e40a6d338 100644 --- a/tests/cron/manager_test.php +++ b/tests/cron/manager_test.php @@ -7,7 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../mock/extension_manager.php'; require_once dirname(__FILE__) . '/includes/cron/task/core/dummy_task.php'; require_once dirname(__FILE__) . '/includes/cron/task/core/second_dummy_task.php'; require_once dirname(__FILE__) . '/ext/testext/cron/dummy_task.php'; diff --git a/tests/cron/task_provider_test.php b/tests/cron/task_provider_test.php index 4547c61a55..b42f40bb4a 100644 --- a/tests/cron/task_provider_test.php +++ b/tests/cron/task_provider_test.php @@ -7,8 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../mock/extension_manager.php'; - class phpbb_cron_task_provider_test extends PHPUnit_Framework_TestCase { public function setUp() diff --git a/tests/download/http_byte_range_test.php b/tests/download/http_byte_range_test.php index b93c1b630c..23b9169fe3 100644 --- a/tests/download/http_byte_range_test.php +++ b/tests/download/http_byte_range_test.php @@ -8,7 +8,6 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_download.php'; -require_once dirname(__FILE__) . '/../mock/request.php'; class phpbb_download_http_byte_range_test extends phpbb_test_case { diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index f7e9bd57bb..622f404786 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -7,9 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../mock/cache.php'; -require_once dirname(__FILE__) . '/../mock/extension_manager.php'; - class phpbb_extension_finder_test extends phpbb_test_case { protected $extension_manager; diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 0a689916c7..45bed247ae 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -7,7 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../mock/cache.php'; require_once dirname(__FILE__) . '/ext/bar/ext.php'; require_once dirname(__FILE__) . '/ext/foo/ext.php'; require_once dirname(__FILE__) . '/ext/vendor/moo/ext.php'; diff --git a/tests/functions_acp/build_cfg_template_test.php b/tests/functions_acp/build_cfg_template_test.php index bb479ffac9..12121f6678 100644 --- a/tests/functions_acp/build_cfg_template_test.php +++ b/tests/functions_acp/build_cfg_template_test.php @@ -7,7 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../mock/lang.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php'; class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case diff --git a/tests/functions_acp/build_select_test.php b/tests/functions_acp/build_select_test.php index 782acae1fa..aca49b7655 100644 --- a/tests/functions_acp/build_select_test.php +++ b/tests/functions_acp/build_select_test.php @@ -7,7 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../mock/lang.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php'; class phpbb_functions_acp_built_select_test extends phpbb_test_case diff --git a/tests/functions_acp/h_radio_test.php b/tests/functions_acp/h_radio_test.php index 02b2444a9e..a61f2e8975 100644 --- a/tests/functions_acp/h_radio_test.php +++ b/tests/functions_acp/h_radio_test.php @@ -7,7 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../mock/lang.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php'; class phpbb_functions_acp_h_radio_test extends phpbb_test_case diff --git a/tests/functions_acp/validate_config_vars_test.php b/tests/functions_acp/validate_config_vars_test.php index 55441561a6..7cd7fa3892 100644 --- a/tests/functions_acp/validate_config_vars_test.php +++ b/tests/functions_acp/validate_config_vars_test.php @@ -7,7 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../mock/lang.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php'; class phpbb_functions_acp_validate_config_vars_test extends phpbb_test_case diff --git a/tests/functions_acp/validate_range_test.php b/tests/functions_acp/validate_range_test.php index 34ce848e76..8606158251 100644 --- a/tests/functions_acp/validate_range_test.php +++ b/tests/functions_acp/validate_range_test.php @@ -7,7 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../mock/lang.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php'; diff --git a/tests/security/base.php b/tests/security/base.php index 82e4dda9d0..08878ad60d 100644 --- a/tests/security/base.php +++ b/tests/security/base.php @@ -7,8 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../mock/request.php'; - abstract class phpbb_security_test_base extends phpbb_test_case { /** diff --git a/tests/session/continue_test.php b/tests/session/continue_test.php index c4f7f8d75b..ad78d92299 100644 --- a/tests/session/continue_test.php +++ b/tests/session/continue_test.php @@ -7,7 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../mock/cache.php'; require_once dirname(__FILE__) . '/testable_factory.php'; class phpbb_session_continue_test extends phpbb_database_test_case diff --git a/tests/session/init_test.php b/tests/session/init_test.php index 2ce6c4a4ac..830de34ed0 100644 --- a/tests/session/init_test.php +++ b/tests/session/init_test.php @@ -7,7 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../mock/cache.php'; require_once dirname(__FILE__) . '/testable_factory.php'; class phpbb_session_init_test extends phpbb_database_test_case diff --git a/tests/session/testable_factory.php b/tests/session/testable_factory.php index a042085908..cb85a01c5c 100644 --- a/tests/session/testable_factory.php +++ b/tests/session/testable_factory.php @@ -7,9 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../mock/request.php'; -require_once dirname(__FILE__) . '/../mock/session_testable.php'; - /** * This class exists to setup an instance of phpbb's session class for testing. * diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index dd0acba6cd..6f76cb049d 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -8,7 +8,6 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../mock/extension_manager.php'; class phpbb_template_template_test_case extends phpbb_test_case { diff --git a/tests/text_processing/censor_text_test.php b/tests/text_processing/censor_text_test.php index 8fcdb7ef85..9da16528d5 100644 --- a/tests/text_processing/censor_text_test.php +++ b/tests/text_processing/censor_text_test.php @@ -9,8 +9,6 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; -require_once dirname(__FILE__) . '/../mock_user.php'; -require_once dirname(__FILE__) . '/../mock/cache.php'; class phpbb_text_processing_censor_text_test extends phpbb_test_case { -- cgit v1.2.1 From 33a13002af3a0a7c6c890393a40b03e92707d934 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Wed, 20 Jun 2012 22:15:59 +0100 Subject: [ticket/10941] Unit tests for filespec class PHPBB3-10941 --- tests/mock/fileupload.php | 23 +++++ tests/uploads/filespec_test.php | 215 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 238 insertions(+) create mode 100644 tests/mock/fileupload.php create mode 100644 tests/uploads/filespec_test.php (limited to 'tests') diff --git a/tests/mock/fileupload.php b/tests/mock/fileupload.php new file mode 100644 index 0000000000..cbcbf4a6ab --- /dev/null +++ b/tests/mock/fileupload.php @@ -0,0 +1,23 @@ + '47494638376101000100800000ffffffffffff2c00000000010001000002024401003b', + 'PNG' => '89504e470d0a1a0a0000000d4948445200000001000000010802000000907753de0000000c4944415408d763f8ffff3f0005fe02fedccc59e70000000049454e44ae426082', + 'TIF' => '49492a000c000000ffffff001000fe00040001000000000000000001030001000000010000000101030001000000010000000201030003000000d20000000301030001000000010000000601030001000000020000000d01020018000000d80000001101040001000000080000001201030001000000010000001501030001000000030000001601030001000000400000001701040001000000030000001a01050001000000f00000001b01050001000000f80000001c0103000100000001000000280103000100000002000000000000000800080008002f686f6d652f6b696d2f746d702f746966662e746966660000000048000000010000004800000001', + 'JPG' => 'ffd8ffe000104a46494600010101004800480000ffdb004300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdb004301ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc20011080001000103012200021101031101ffc4001500010100000000000000000000000000000002ffc40014010100000000000000000000000000000000ffda000c03010002100310000001a07fffc40014100100000000000000000000000000000000ffda00080101000105027fffc40014110100000000000000000000000000000000ffda0008010301013f017fffc40014110100000000000000000000000000000000ffda0008010201013f017fffc40014100100000000000000000000000000000000ffda0008010100063f027fffc40014100100000000000000000000000000000000ffda0008010100013f217fffda000c0301000200030000001003ffc40014110100000000000000000000000000000000ffda0008010301013f107fffc40014110100000000000000000000000000000000ffda0008010201013f107fffc40014100100000000000000000000000000000000ffda0008010100013f107fffd9', + ); + + private $config; + private $filespec; + + protected function setUp() + { + global $config; + + if (!is_array($config)) + { + $config = array(); + } + + $config['rand_seed'] = ''; + $config['rand_seed_last_update'] = time() + 600; + $config['mime_triggers'] = 'body|head|html|img|plaintext|a href|pre|script|table|title'; + $this->config = $config; + + // Write some data to files + $path = dirname(__FILE__) . '/../../phpBB/files/'; + foreach (phpbb_filespec_test::$files as $type => $data) + { + file_put_contents($path . $type, hex2bin($data)); + } + + file_put_contents($path . 'TXT', 'mime trigger'); + + $this->init_filespec(); + } + + public static function additional_checks_variables() + { + $path = dirname(__FILE__) . '/../../phpBB/files/'; + return array( + array($path . 'GIF', true), + array($path . 'JPG', false), + array($path . 'PNG', true), + array($path . 'TIF', false), + array($path . 'TXT', true), + ); + } + + public static function check_content_variables() + { + $path = dirname(__FILE__) . '/../../phpBB/files/'; + $vars = array(); + foreach (phpbb_filespec_test::$files as $type => $data) + { + $vars[] = array($path . $type, true); + } + + $vars[] = array($path . 'TXT', false); + return $vars; + } + + public static function get_extension_variables() + { + return array( + array('file.png', 'png'), + array('file.phpbb.gif', 'gif'), + array('file..', ''), + array('.file..jpg.webp', 'webp'), + ); + } + + private function init_filespec($override = array()) + { + // Initialise a blank filespec object for use with trivial methods + $upload_ary = array( + 'name' => '', + 'type' => '', + 'size' => '', + 'tmp_name' => '', + 'error' => '', + ); + + $this->filespec = new filespec(array_merge($upload_ary, $override), null); + } + + public static function is_image_variables() + { + $path = dirname(__FILE__) . '/../../phpBB/files/'; + $vars = array(); + foreach (phpbb_filespec_test::$files as $type => $data) + { + $vars[] = array($path . $type, 'image/' . $type, true); + } + + $vars[] = array($path . 'TXT', 'text/plain', false); + return $vars; + } + + protected function tearDown() + { + $path = dirname(__FILE__) . '/../../phpBB/files/'; + unlink($path . 'TXT'); + foreach (phpbb_filespec_test::$files as $type => $data) + { + unlink($path . $type); + } + } + + /** + * @dataProvider additional_checks_variables + */ + public function test_additional_checks($filename, $expected) + { + global $user; + $user = new phpbb_mock_user(); + + $upload = new phpbb_mock_fileupload(); + $this->init_filespec(array('tmp_name', $filename)); + $this->filespec->upload = $upload; + $this->filespec->file_moved = true; + $this->filespec->filesize = $this->filespec->get_filesize($filename); + + $this->assertEquals($expected, $this->filespec->additional_checks()); + } + + /** + * @dataProvider check_content_variables + */ + public function test_check_content($filename, $expected) + { + $disallowed_content = explode('|', $this->config['mime_triggers']); + $this->init_filespec(array('tmp_name' => $filename)); + $this->assertEquals($expected, $this->filespec->check_content($disallowed_content)); + } + + public function test_clean_filename_real() + { + $available_chars = str_split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\'\\" /:*?<>|[];(){},#+=-_`'); + $bad_chars = array("'", "\\", ' ', '/', ':', '*', '?', '"', '<', '>', '|'); + for ($tests = 0; $tests < self::TEST_COUNT; $tests++) + { + $len = mt_rand(1, self::MAX_STR_LEN); + $str = ''; + for ($j = 0; $j < $len; $j++) + { + $index = mt_rand(0, sizeof($available_chars) - 1); + $str .= $available_chars[$index]; + } + + $this->init_filespec(array('name' => $str)); + $this->filespec->clean_filename('real', self::PREFIX); + $name = $this->filespec->realname; + + $this->assertEquals(0, preg_match('/%(\w{2})/', $name)); + foreach ($bad_chars as $char) + { + $this->assertFalse(strpos($name, $char)); + } + } + } + + public function test_clean_filename_unique() + { + $filenames = array(); + for ($tests = 0; $tests < self::TEST_COUNT; $tests++) + { + $this->init_filespec(); + $this->filespec->clean_filename('unique', self::PREFIX); + $name = $this->filespec->realname; + + $this->assertTrue(strlen($name) === 32 + strlen(self::PREFIX)); + $this->assertRegExp('#^[A-Za-z0-9]+$#', substr($name, strlen(self::PREFIX))); + $this->assertFalse(isset($filenames[$name])); + $filenames[$name] = true; + } + } + + /** + * @dataProvider get_extension_variables + */ + public function test_get_extension($filename, $expected) + { + $this->assertEquals($expected, $this->filespec->get_extension($filename)); + } + + /** + * @dataProvider is_image_variables + */ + public function test_is_image($filename, $mimetype, $expected) + { + $this->init_filespec(array('tmp_name' => $filename, 'type' => $mimetype)); + $this->assertEquals($expected, $this->filespec->is_image()); + } +} -- cgit v1.2.1 From d6bd8928b533e297cf2812bfe013cbf15c5863b8 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Thu, 21 Jun 2012 12:22:08 +0100 Subject: [ticket/10941] Minor adjustments as per PR comments Switched from dirname(__FILE__) to just __DIR__. Removed static definition from data provider methods. PHPBB3-10941 --- tests/uploads/filespec_test.php | 100 ++++++++++++++-------------------------- tests/uploads/fixture/GIF | Bin 0 -> 35 bytes tests/uploads/fixture/JPG | Bin 0 -> 519 bytes tests/uploads/fixture/PNG | Bin 0 -> 69 bytes tests/uploads/fixture/TIF | Bin 0 -> 256 bytes tests/uploads/fixture/TXT | 1 + 6 files changed, 36 insertions(+), 65 deletions(-) create mode 100644 tests/uploads/fixture/GIF create mode 100644 tests/uploads/fixture/JPG create mode 100644 tests/uploads/fixture/PNG create mode 100644 tests/uploads/fixture/TIF create mode 100644 tests/uploads/fixture/TXT (limited to 'tests') diff --git a/tests/uploads/filespec_test.php b/tests/uploads/filespec_test.php index 401ff545e6..0eb96e3c4a 100644 --- a/tests/uploads/filespec_test.php +++ b/tests/uploads/filespec_test.php @@ -2,15 +2,15 @@ /** * * @package testing - * @copyright (c) 20012 phpBB Group + * @copyright (c) 2012 phpBB Group * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/functions_upload.php'; -require_once dirname(__FILE__) . '/../mock/fileupload.php'; +require_once __DIR__ . '/../../phpBB/includes/functions.php'; +require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php'; +require_once __DIR__ . '/../../phpBB/includes/functions_upload.php'; +require_once __DIR__ . '/../mock/fileupload.php'; class phpbb_filespec_test extends phpbb_test_case { @@ -18,16 +18,9 @@ class phpbb_filespec_test extends phpbb_test_case const PREFIX = 'phpbb_'; const MAX_STR_LEN = 50; - // Hexadecimal encoded images - public static $files = array( - 'GIF' => '47494638376101000100800000ffffffffffff2c00000000010001000002024401003b', - 'PNG' => '89504e470d0a1a0a0000000d4948445200000001000000010802000000907753de0000000c4944415408d763f8ffff3f0005fe02fedccc59e70000000049454e44ae426082', - 'TIF' => '49492a000c000000ffffff001000fe00040001000000000000000001030001000000010000000101030001000000010000000201030003000000d20000000301030001000000010000000601030001000000020000000d01020018000000d80000001101040001000000080000001201030001000000010000001501030001000000030000001601030001000000400000001701040001000000030000001a01050001000000f00000001b01050001000000f80000001c0103000100000001000000280103000100000002000000000000000800080008002f686f6d652f6b696d2f746d702f746966662e746966660000000048000000010000004800000001', - 'JPG' => 'ffd8ffe000104a46494600010101004800480000ffdb004300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdb004301ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc20011080001000103012200021101031101ffc4001500010100000000000000000000000000000002ffc40014010100000000000000000000000000000000ffda000c03010002100310000001a07fffc40014100100000000000000000000000000000000ffda00080101000105027fffc40014110100000000000000000000000000000000ffda0008010301013f017fffc40014110100000000000000000000000000000000ffda0008010201013f017fffc40014100100000000000000000000000000000000ffda0008010100063f027fffc40014100100000000000000000000000000000000ffda0008010100013f217fffda000c0301000200030000001003ffc40014110100000000000000000000000000000000ffda0008010301013f107fffc40014110100000000000000000000000000000000ffda0008010201013f107fffc40014100100000000000000000000000000000000ffda0008010100013f107fffd9', - ); - private $config; private $filespec; + public $path; protected function setUp() { @@ -41,46 +34,35 @@ class phpbb_filespec_test extends phpbb_test_case $config['rand_seed'] = ''; $config['rand_seed_last_update'] = time() + 600; $config['mime_triggers'] = 'body|head|html|img|plaintext|a href|pre|script|table|title'; - $this->config = $config; - - // Write some data to files - $path = dirname(__FILE__) . '/../../phpBB/files/'; - foreach (phpbb_filespec_test::$files as $type => $data) - { - file_put_contents($path . $type, hex2bin($data)); - } - - file_put_contents($path . 'TXT', 'mime trigger'); + $this->config = $config; + $this->path = __DIR__ . '/fixture/'; $this->init_filespec(); } - public static function additional_checks_variables() + public function additional_checks_variables() { - $path = dirname(__FILE__) . '/../../phpBB/files/'; return array( - array($path . 'GIF', true), - array($path . 'JPG', false), - array($path . 'PNG', true), - array($path . 'TIF', false), - array($path . 'TXT', true), + array('GIF', true), + array('JPG', false), + array('PNG', true), + array('TIF', false), + array('TXT', true), ); } - public static function check_content_variables() + public function check_content_variables() { - $path = dirname(__FILE__) . '/../../phpBB/files/'; - $vars = array(); - foreach (phpbb_filespec_test::$files as $type => $data) - { - $vars[] = array($path . $type, true); - } - - $vars[] = array($path . 'TXT', false); - return $vars; + return array( + array('GIF', true), + array('JPG', true), + array('PNG', true), + array('TIF', true), + array('TXT', false), + ); } - public static function get_extension_variables() + public function get_extension_variables() { return array( array('file.png', 'png'), @@ -104,27 +86,15 @@ class phpbb_filespec_test extends phpbb_test_case $this->filespec = new filespec(array_merge($upload_ary, $override), null); } - public static function is_image_variables() + public function is_image_variables() { - $path = dirname(__FILE__) . '/../../phpBB/files/'; - $vars = array(); - foreach (phpbb_filespec_test::$files as $type => $data) - { - $vars[] = array($path . $type, 'image/' . $type, true); - } - - $vars[] = array($path . 'TXT', 'text/plain', false); - return $vars; - } - - protected function tearDown() - { - $path = dirname(__FILE__) . '/../../phpBB/files/'; - unlink($path . 'TXT'); - foreach (phpbb_filespec_test::$files as $type => $data) - { - unlink($path . $type); - } + return array( + array('GIF', 'image/gif', true), + array('JPG', 'image/jpg', true), + array('PNG', 'image/png', true), + array('TIF', 'image/tif', true), + array('TXT', 'text/plain', false), + ); } /** @@ -136,10 +106,10 @@ class phpbb_filespec_test extends phpbb_test_case $user = new phpbb_mock_user(); $upload = new phpbb_mock_fileupload(); - $this->init_filespec(array('tmp_name', $filename)); + $this->init_filespec(array('tmp_name', $this->path . $filename)); $this->filespec->upload = $upload; $this->filespec->file_moved = true; - $this->filespec->filesize = $this->filespec->get_filesize($filename); + $this->filespec->filesize = $this->filespec->get_filesize($this->path . $filename); $this->assertEquals($expected, $this->filespec->additional_checks()); } @@ -150,7 +120,7 @@ class phpbb_filespec_test extends phpbb_test_case public function test_check_content($filename, $expected) { $disallowed_content = explode('|', $this->config['mime_triggers']); - $this->init_filespec(array('tmp_name' => $filename)); + $this->init_filespec(array('tmp_name' => $this->path . $filename)); $this->assertEquals($expected, $this->filespec->check_content($disallowed_content)); } @@ -209,7 +179,7 @@ class phpbb_filespec_test extends phpbb_test_case */ public function test_is_image($filename, $mimetype, $expected) { - $this->init_filespec(array('tmp_name' => $filename, 'type' => $mimetype)); + $this->init_filespec(array('tmp_name' => $this->path . $filename, 'type' => $mimetype)); $this->assertEquals($expected, $this->filespec->is_image()); } } diff --git a/tests/uploads/fixture/GIF b/tests/uploads/fixture/GIF new file mode 100644 index 0000000000..b636f4b8df Binary files /dev/null and b/tests/uploads/fixture/GIF differ diff --git a/tests/uploads/fixture/JPG b/tests/uploads/fixture/JPG new file mode 100644 index 0000000000..3cd5038e38 Binary files /dev/null and b/tests/uploads/fixture/JPG differ diff --git a/tests/uploads/fixture/PNG b/tests/uploads/fixture/PNG new file mode 100644 index 0000000000..5514ad40e9 Binary files /dev/null and b/tests/uploads/fixture/PNG differ diff --git a/tests/uploads/fixture/TIF b/tests/uploads/fixture/TIF new file mode 100644 index 0000000000..248b50f9cb Binary files /dev/null and b/tests/uploads/fixture/TIF differ diff --git a/tests/uploads/fixture/TXT b/tests/uploads/fixture/TXT new file mode 100644 index 0000000000..d3c40d2ea7 --- /dev/null +++ b/tests/uploads/fixture/TXT @@ -0,0 +1 @@ +mime trigger -- cgit v1.2.1 From fe4056c599f1e90789997bd8af391aa024c05075 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Thu, 21 Jun 2012 14:27:39 +0100 Subject: [ticket/10941] Finished filespec tests PHPBB3-10941 --- tests/mock/fileupload.php | 22 +++++++++++++ tests/uploads/filespec_test.php | 69 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) (limited to 'tests') diff --git a/tests/mock/fileupload.php b/tests/mock/fileupload.php index cbcbf4a6ab..817b090346 100644 --- a/tests/mock/fileupload.php +++ b/tests/mock/fileupload.php @@ -20,4 +20,26 @@ class phpbb_mock_fileupload { return true; } + + public function image_types() + { + return array( + IMAGETYPE_GIF => array('gif'), + IMAGETYPE_JPEG => array('jpg', 'jpeg'), + IMAGETYPE_PNG => array('png'), + IMAGETYPE_SWF => array('swf'), + IMAGETYPE_PSD => array('psd'), + IMAGETYPE_BMP => array('bmp'), + IMAGETYPE_TIFF_II => array('tif', 'tiff'), + IMAGETYPE_TIFF_MM => array('tif', 'tiff'), + IMAGETYPE_JPC => array('jpg', 'jpeg'), + IMAGETYPE_JP2 => array('jpg', 'jpeg'), + IMAGETYPE_JPX => array('jpg', 'jpeg'), + IMAGETYPE_JB2 => array('jpg', 'jpeg'), + IMAGETYPE_SWC => array('swc'), + IMAGETYPE_IFF => array('iff'), + IMAGETYPE_WBMP => array('wbmp'), + IMAGETYPE_XBM => array('xbm'), + ); + } } diff --git a/tests/uploads/filespec_test.php b/tests/uploads/filespec_test.php index 0eb96e3c4a..97ccb8db61 100644 --- a/tests/uploads/filespec_test.php +++ b/tests/uploads/filespec_test.php @@ -11,12 +11,14 @@ require_once __DIR__ . '/../../phpBB/includes/functions.php'; require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php'; require_once __DIR__ . '/../../phpBB/includes/functions_upload.php'; require_once __DIR__ . '/../mock/fileupload.php'; +require_once __DIR__ . '/../mock/request.php'; class phpbb_filespec_test extends phpbb_test_case { const TEST_COUNT = 100; const PREFIX = 'phpbb_'; const MAX_STR_LEN = 50; + const UPLOAD_MAX_FILESIZE = 1000; private $config; private $filespec; @@ -38,6 +40,22 @@ class phpbb_filespec_test extends phpbb_test_case $this->config = $config; $this->path = __DIR__ . '/fixture/'; $this->init_filespec(); + + // Create copies of the files for use in testing move_file + $it = new DirectoryIterator($this->path); + foreach ($it as $fileinfo) + { + if ($fileinfo->isDot()) + { + continue; + } + + copy($fileinfo->getPathname(), $this->path . $fileinfo->getFilename() . '_copy'); + if ($fileinfo->getFilename() === 'TXT') + { + copy($fileinfo->getPathname(), $this->path . $fileinfo->getFilename() . '_copy_2'); + } + } } public function additional_checks_variables() @@ -97,6 +115,30 @@ class phpbb_filespec_test extends phpbb_test_case ); } + public function move_file_variables() + { + return array( + array('GIF_copy', 'GIF_moved', 'image/gif', 'gif', false, true), + array('non_existant', 'still_non_existant', 'text/plain', 'txt', true, false), + array('TXT_copy', 'TXT_as_img', 'image/jpg', 'txt', true, true), + array('TXT_copy_2', 'TXT_moved', 'text/plain', 'txt', false, true), + array('JPG_copy', 'JPG_moved', 'image/png', 'jpg', false, true), + array('PNG_copy', 'PNG_moved', 'image/png', 'jpg', true, true), + ); + } + + protected function tearDown() + { + $it = new DirectoryIterator($this->path); + foreach ($it as $fileinfo) + { + if (strlen($fileinfo->getFilename()) > 3) + { + unlink($fileinfo->getPathname()); + } + } + } + /** * @dataProvider additional_checks_variables */ @@ -182,4 +224,31 @@ class phpbb_filespec_test extends phpbb_test_case $this->init_filespec(array('tmp_name' => $this->path . $filename, 'type' => $mimetype)); $this->assertEquals($expected, $this->filespec->is_image()); } + + /** + * @dataProvider move_file_variables + */ + public function test_move_file($tmp_name, $realname, $mime_type, $extension, $error, $expected) + { + global $request, $phpbb_root_path, $phpEx; + $phpbb_root_path = ''; + $phpEx = 'php'; + $request = new phpbb_mock_request(); + + $upload = new phpbb_mock_fileupload(); + $upload->max_filesize = self::UPLOAD_MAX_FILESIZE; + + $this->init_filespec(array( + 'tmp_name' => $this->path . $tmp_name, + 'name' => $realname, + 'type' => $mime_type, + )); + $this->filespec->extension = $extension; + $this->filespec->upload = $upload; + $this->filespec->local = true; + + $this->assertEquals($expected, $this->filespec->move_file($this->path)); + $this->assertEquals($error, (bool) sizeof($this->filespec->error)); + $this->assertEquals($this->filespec->file_moved, file_exists($this->path . $realname)); + } } -- cgit v1.2.1 From dfef80f267f19b21dbf5b94ac43ecc856da65aef Mon Sep 17 00:00:00 2001 From: Fyorl Date: Thu, 21 Jun 2012 16:42:09 +0100 Subject: [ticket/10941] Unit tests for fileupload class added PHPBB3-10941 --- tests/mock/filespec.php | 32 ++++++++++++ tests/uploads/common.php | 0 tests/uploads/fileupload_test.php | 100 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 tests/mock/filespec.php create mode 100644 tests/uploads/common.php create mode 100644 tests/uploads/fileupload_test.php (limited to 'tests') diff --git a/tests/mock/filespec.php b/tests/mock/filespec.php new file mode 100644 index 0000000000..9d2a5c84de --- /dev/null +++ b/tests/mock/filespec.php @@ -0,0 +1,32 @@ +$property; + } +} diff --git a/tests/uploads/common.php b/tests/uploads/common.php new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/uploads/fileupload_test.php b/tests/uploads/fileupload_test.php new file mode 100644 index 0000000000..1fa628cbf9 --- /dev/null +++ b/tests/uploads/fileupload_test.php @@ -0,0 +1,100 @@ +path = __DIR__ . '/fixture/'; + } + + private function gen_valid_filespec() + { + $filespec = new phpbb_mock_filespec(); + $filespec->filesize = 1; + $filespec->extension = 'jpg'; + $filespec->realname = 'valid'; + $filespec->width = 2; + $filespec->height = 2; + + return $filespec; + } + + public function test_common_checks() + { + // Test 1: Valid file + $upload = new fileupload('', array('jpg'), 1000); + $file = $this->gen_valid_filespec(); + $upload->common_checks($file); + $this->assertEquals(0, sizeof($file->error)); + + // Test 2: File too large + $upload = new fileupload('', array('jpg'), 100); + $file = $this->gen_valid_filespec(); + $file->filesize = 1000; + $upload->common_checks($file); + $this->assertEquals(1, sizeof($file->error)); + + // Test 3: Invalid filename + $upload = new fileupload('', array('jpg'), 100); + $file = $this->gen_valid_filespec(); + $file->realname = 'invalid?'; + $upload->common_checks($file); + $this->assertEquals(1, sizeof($file->error)); + + // Test 4: Invalid extension + $upload = new fileupload('', array('png'), 100); + $file = $this->gen_valid_filespec(); + $upload->common_checks($file); + $this->assertEquals(1, sizeof($file->error)); + } + + public function test_local_upload() + { + $upload = new fileupload('', array('jpg'), 1000); + + copy($this->path . 'JPG', $this->path . 'JPG.jpg'); + $file = $upload->local_upload($this->path . 'JPG.jpg'); + $this->assertEquals(0, sizeof($file->error)); + unlink($this->path . 'JPG.jpg'); + } + + public function test_valid_dimensions() + { + $upload = new fileupload('', false, false, 1, 1, 100, 100); + + $file1 = $this->gen_valid_filespec(); + $file2 = $this->gen_valid_filespec(); + $file2->height = 101; + $file3 = $this->gen_valid_filespec(); + $file3->width = 0; + + $this->assertTrue($upload->valid_dimensions($file1)); + $this->assertFalse($upload->valid_dimensions($file2)); + $this->assertFalse($upload->valid_dimensions($file3)); + } +} -- cgit v1.2.1 From 5693036bf9237ad54e62425faf6ab16907cc7ea9 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Fri, 22 Jun 2012 18:39:02 +0100 Subject: [ticket/10941] Added functional tests for the fileupload class NOTE: test_form_upload() is broken. Uploading files via Symfony fails to retain $_FILES['fileupload']['type'] even if it set explicitely. This appears to be a bug in Symfony. Since the current version of filespec::is_image() relies on the mimetype, these tests will __fail__. filespec::is_image() has been fixed in https://github.com/phpbb/phpbb3/pull/833 however. PHPBB3-10941 --- tests/functional/fileupload_test.php | 86 +++++++++++++++++++++ tests/functional/fixtures/files/empty.png | 0 .../fixtures/files/illegal-extension.bif | Bin 0 -> 519 bytes tests/functional/fixtures/files/too-large.png | Bin 0 -> 284717 bytes tests/functional/fixtures/files/valid.jpg | Bin 0 -> 554 bytes 5 files changed, 86 insertions(+) create mode 100644 tests/functional/fileupload_test.php create mode 100644 tests/functional/fixtures/files/empty.png create mode 100644 tests/functional/fixtures/files/illegal-extension.bif create mode 100644 tests/functional/fixtures/files/too-large.png create mode 100644 tests/functional/fixtures/files/valid.jpg (limited to 'tests') diff --git a/tests/functional/fileupload_test.php b/tests/functional/fileupload_test.php new file mode 100644 index 0000000000..ff62bad7bd --- /dev/null +++ b/tests/functional/fileupload_test.php @@ -0,0 +1,86 @@ +add_lang('posting'); + $this->login(); + + // Test 1: Invalid extension + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($path . 'illegal-extension.bif'); + $crawler = $this->client->submit($form); + $this->assertEquals(1, $crawler->filter('p.error')->count()); + + // Test 2: Empty file + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($path . 'empty.png'); + $crawler = $this->client->submit($form); + $this->assertEquals(1, $crawler->filter('p.error')->count()); + + // Test 3: File too large + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($path . 'too-large.png'); + $crawler = $this->client->submit($form); + $this->assertEquals(1, $crawler->filter('div#message')->count()); + + // Test 4: Valid file + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($path . 'valid.jpg'); + $crawler = $this->client->submit($form); + $this->assertEquals(0, $crawler->filter('p.error')->count()); + $this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->eq(1)->text()); + } + + public function test_remote_upload() + { + // Only doing this within the functional framework because we need a + // URL + global $config; + + if (!is_array($config)) + { + $config = array(); + } + + $config['rand_seed'] = ''; + $config['rand_seed_last_update'] = time() + 600; + + // Test 1: Invalid extension + $upload = new fileupload('', array('jpg'), 100); + $file = $upload->remote_upload('http://example.com/image.gif'); + $this->assertEquals(1, sizeof($file->error)); + + // Test 2: Non-existant file + $upload = new fileupload('', array('jpg'), 100); + $file = $upload->remote_upload('http://example.com/image.jpg'); + $this->assertEquals(1, sizeof($file->error)); + + // Test 3: File too large + $upload = new fileupload('', array('gif'), 100); + $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $this->assertEquals(1, sizeof($file->error)); + + // Test 4: Successful upload + $upload = new fileupload('', array('gif'), 1000); + $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $this->assertEquals(0, sizeof($file->error)); + $this->assertTrue(file_exists($file->filename)); + } +} diff --git a/tests/functional/fixtures/files/empty.png b/tests/functional/fixtures/files/empty.png new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/functional/fixtures/files/illegal-extension.bif b/tests/functional/fixtures/files/illegal-extension.bif new file mode 100644 index 0000000000..3cd5038e38 Binary files /dev/null and b/tests/functional/fixtures/files/illegal-extension.bif differ diff --git a/tests/functional/fixtures/files/too-large.png b/tests/functional/fixtures/files/too-large.png new file mode 100644 index 0000000000..ed4b0abd80 Binary files /dev/null and b/tests/functional/fixtures/files/too-large.png differ diff --git a/tests/functional/fixtures/files/valid.jpg b/tests/functional/fixtures/files/valid.jpg new file mode 100644 index 0000000000..95a87ddbdf Binary files /dev/null and b/tests/functional/fixtures/files/valid.jpg differ -- cgit v1.2.1 From 1233544c4a280e4392af448df654b5263e8c35db Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 25 Jun 2012 00:23:02 +0100 Subject: [ticket/10941] Marked broken test as incomplete PHPBB3-10941 --- tests/functional/fileupload_test.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/functional/fileupload_test.php b/tests/functional/fileupload_test.php index ff62bad7bd..c06f7d94d7 100644 --- a/tests/functional/fileupload_test.php +++ b/tests/functional/fileupload_test.php @@ -14,6 +14,7 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case { public function test_form_upload() { + $this->markTestIncomplete(); $path = __DIR__ . '/fixtures/files/'; $this->add_lang('posting'); $this->login(); -- cgit v1.2.1 From 82ca2c8b08ca8c21b358ee8c862c639a5944977d Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sat, 30 Jun 2012 10:41:54 +0100 Subject: [ticket/10941] Minor adjustments as per PR comments Added some comments clarifying globals and lowercased fixture filenames PHPBB3-10941 --- tests/functional/fileupload_test.php | 8 +++ tests/uploads/filespec_test.php | 100 ++++++++++++++++++++--------------- tests/uploads/fileupload_test.php | 20 +++++-- tests/uploads/fixture/GIF | Bin 35 -> 0 bytes tests/uploads/fixture/JPG | Bin 519 -> 0 bytes tests/uploads/fixture/PNG | Bin 69 -> 0 bytes tests/uploads/fixture/TIF | Bin 256 -> 0 bytes tests/uploads/fixture/TXT | 1 - tests/uploads/fixture/gif | Bin 0 -> 35 bytes tests/uploads/fixture/jpg | Bin 0 -> 519 bytes tests/uploads/fixture/png | Bin 0 -> 69 bytes tests/uploads/fixture/tif | Bin 0 -> 256 bytes tests/uploads/fixture/txt | 1 + 13 files changed, 82 insertions(+), 48 deletions(-) delete mode 100644 tests/uploads/fixture/GIF delete mode 100644 tests/uploads/fixture/JPG delete mode 100644 tests/uploads/fixture/PNG delete mode 100644 tests/uploads/fixture/TIF delete mode 100644 tests/uploads/fixture/TXT create mode 100644 tests/uploads/fixture/gif create mode 100644 tests/uploads/fixture/jpg create mode 100644 tests/uploads/fixture/png create mode 100644 tests/uploads/fixture/tif create mode 100644 tests/uploads/fixture/txt (limited to 'tests') diff --git a/tests/functional/fileupload_test.php b/tests/functional/fileupload_test.php index c06f7d94d7..bbcc0c37c9 100644 --- a/tests/functional/fileupload_test.php +++ b/tests/functional/fileupload_test.php @@ -51,8 +51,14 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case public function test_remote_upload() { + // Note: we cannot check for the actual value of the error messages + // since they are passed through the translator which will result in + // blank strings within this test framework. + // Only doing this within the functional framework because we need a // URL + + // Global $config required by unique_id global $config; if (!is_array($config)) @@ -83,5 +89,7 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); $this->assertEquals(0, sizeof($file->error)); $this->assertTrue(file_exists($file->filename)); + + $config = array(); } } diff --git a/tests/uploads/filespec_test.php b/tests/uploads/filespec_test.php index 97ccb8db61..3c9eda4468 100644 --- a/tests/uploads/filespec_test.php +++ b/tests/uploads/filespec_test.php @@ -26,6 +26,7 @@ class phpbb_filespec_test extends phpbb_test_case protected function setUp() { + // Global $config required by unique_id global $config; if (!is_array($config)) @@ -37,7 +38,7 @@ class phpbb_filespec_test extends phpbb_test_case $config['rand_seed_last_update'] = time() + 600; $config['mime_triggers'] = 'body|head|html|img|plaintext|a href|pre|script|table|title'; - $this->config = $config; + $this->config = &$config; $this->path = __DIR__ . '/fixture/'; $this->init_filespec(); @@ -51,7 +52,7 @@ class phpbb_filespec_test extends phpbb_test_case } copy($fileinfo->getPathname(), $this->path . $fileinfo->getFilename() . '_copy'); - if ($fileinfo->getFilename() === 'TXT') + if ($fileinfo->getFilename() === 'txt') { copy($fileinfo->getPathname(), $this->path . $fileinfo->getFilename() . '_copy_2'); } @@ -61,22 +62,34 @@ class phpbb_filespec_test extends phpbb_test_case public function additional_checks_variables() { return array( - array('GIF', true), - array('JPG', false), - array('PNG', true), - array('TIF', false), - array('TXT', true), + array('gif', true), + array('jpg', false), + array('png', true), + array('tif', false), + array('txt', true), ); } public function check_content_variables() { return array( - array('GIF', true), - array('JPG', true), - array('PNG', true), - array('TIF', true), - array('TXT', false), + array('gif', true), + array('jpg', true), + array('png', true), + array('tif', true), + array('txt', false), + ); + } + + public function clean_filename_variables() + { + $chunks = str_split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\'\\" /:*?<>|[];(){},#+=-_`', 8); + return array( + array($chunks[0] . $chunks[7]), + array($chunks[1] . $chunks[8]), + array($chunks[2] . $chunks[9]), + array($chunks[3] . $chunks[4]), + array($chunks[5] . $chunks[6]), ); } @@ -107,23 +120,23 @@ class phpbb_filespec_test extends phpbb_test_case public function is_image_variables() { return array( - array('GIF', 'image/gif', true), - array('JPG', 'image/jpg', true), - array('PNG', 'image/png', true), - array('TIF', 'image/tif', true), - array('TXT', 'text/plain', false), + array('gif', 'image/gif', true), + array('jpg', 'image/jpg', true), + array('png', 'image/png', true), + array('tif', 'image/tif', true), + array('txt', 'text/plain', false), ); } public function move_file_variables() { return array( - array('GIF_copy', 'GIF_moved', 'image/gif', 'gif', false, true), + array('gif_copy', 'gif_moved', 'image/gif', 'gif', false, true), array('non_existant', 'still_non_existant', 'text/plain', 'txt', true, false), - array('TXT_copy', 'TXT_as_img', 'image/jpg', 'txt', true, true), - array('TXT_copy_2', 'TXT_moved', 'text/plain', 'txt', false, true), - array('JPG_copy', 'JPG_moved', 'image/png', 'jpg', false, true), - array('PNG_copy', 'PNG_moved', 'image/png', 'jpg', true, true), + array('txt_copy', 'txt_as_img', 'image/jpg', 'txt', true, true), + array('txt_copy_2', 'txt_moved', 'text/plain', 'txt', false, true), + array('jpg_copy', 'jpg_moved', 'image/png', 'jpg', false, true), + array('png_copy', 'png_moved', 'image/png', 'jpg', true, true), ); } @@ -137,6 +150,8 @@ class phpbb_filespec_test extends phpbb_test_case unlink($fileinfo->getPathname()); } } + + $this->config = array(); } /** @@ -144,6 +159,7 @@ class phpbb_filespec_test extends phpbb_test_case */ public function test_additional_checks($filename, $expected) { + // Global $user required by filespec::additional_checks global $user; $user = new phpbb_mock_user(); @@ -154,6 +170,8 @@ class phpbb_filespec_test extends phpbb_test_case $this->filespec->filesize = $this->filespec->get_filesize($this->path . $filename); $this->assertEquals($expected, $this->filespec->additional_checks()); + + $user = null; } /** @@ -166,29 +184,21 @@ class phpbb_filespec_test extends phpbb_test_case $this->assertEquals($expected, $this->filespec->check_content($disallowed_content)); } - public function test_clean_filename_real() + /** + * @dataProvider clean_filename_variables + */ + public function test_clean_filename_real($filename) { - $available_chars = str_split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\'\\" /:*?<>|[];(){},#+=-_`'); + $bad_chars = array("'", "\\", ' ', '/', ':', '*', '?', '"', '<', '>', '|'); - for ($tests = 0; $tests < self::TEST_COUNT; $tests++) - { - $len = mt_rand(1, self::MAX_STR_LEN); - $str = ''; - for ($j = 0; $j < $len; $j++) - { - $index = mt_rand(0, sizeof($available_chars) - 1); - $str .= $available_chars[$index]; - } - - $this->init_filespec(array('name' => $str)); - $this->filespec->clean_filename('real', self::PREFIX); - $name = $this->filespec->realname; + $this->init_filespec(array('name' => $filename)); + $this->filespec->clean_filename('real', self::PREFIX); + $name = $this->filespec->realname; - $this->assertEquals(0, preg_match('/%(\w{2})/', $name)); - foreach ($bad_chars as $char) - { - $this->assertFalse(strpos($name, $char)); - } + $this->assertEquals(0, preg_match('/%(\w{2})/', $name)); + foreach ($bad_chars as $char) + { + $this->assertFalse(strpos($name, $char)); } } @@ -230,10 +240,10 @@ class phpbb_filespec_test extends phpbb_test_case */ public function test_move_file($tmp_name, $realname, $mime_type, $extension, $error, $expected) { - global $request, $phpbb_root_path, $phpEx; + // Global $phpbb_root_path and $phpEx are required by phpbb_chmod + global $phpbb_root_path, $phpEx; $phpbb_root_path = ''; $phpEx = 'php'; - $request = new phpbb_mock_request(); $upload = new phpbb_mock_fileupload(); $upload->max_filesize = self::UPLOAD_MAX_FILESIZE; @@ -250,5 +260,7 @@ class phpbb_filespec_test extends phpbb_test_case $this->assertEquals($expected, $this->filespec->move_file($this->path)); $this->assertEquals($error, (bool) sizeof($this->filespec->error)); $this->assertEquals($this->filespec->file_moved, file_exists($this->path . $realname)); + + $phpEx = ''; } } diff --git a/tests/uploads/fileupload_test.php b/tests/uploads/fileupload_test.php index 1fa628cbf9..cb346fd0a2 100644 --- a/tests/uploads/fileupload_test.php +++ b/tests/uploads/fileupload_test.php @@ -18,6 +18,8 @@ class phpbb_fileupload_test extends phpbb_test_case protected function setUp() { + // Global $config required by unique_id + // Global $user required by several functions dealing with translations global $config, $user; if (!is_array($config)) @@ -44,8 +46,20 @@ class phpbb_fileupload_test extends phpbb_test_case return $filespec; } + protected function tearDown() + { + // Clear globals + global $config, $user; + $config = array(); + $user = null; + } + public function test_common_checks() { + // Note: we cannot check for the actual value of the error messages + // since they are passed through the translator which will result in + // blank strings within this test framework. + // Test 1: Valid file $upload = new fileupload('', array('jpg'), 1000); $file = $this->gen_valid_filespec(); @@ -77,10 +91,10 @@ class phpbb_fileupload_test extends phpbb_test_case { $upload = new fileupload('', array('jpg'), 1000); - copy($this->path . 'JPG', $this->path . 'JPG.jpg'); - $file = $upload->local_upload($this->path . 'JPG.jpg'); + copy($this->path . 'jpg', $this->path . 'jpg.jpg'); + $file = $upload->local_upload($this->path . 'jpg.jpg'); $this->assertEquals(0, sizeof($file->error)); - unlink($this->path . 'JPG.jpg'); + unlink($this->path . 'jpg.jpg'); } public function test_valid_dimensions() diff --git a/tests/uploads/fixture/GIF b/tests/uploads/fixture/GIF deleted file mode 100644 index b636f4b8df..0000000000 Binary files a/tests/uploads/fixture/GIF and /dev/null differ diff --git a/tests/uploads/fixture/JPG b/tests/uploads/fixture/JPG deleted file mode 100644 index 3cd5038e38..0000000000 Binary files a/tests/uploads/fixture/JPG and /dev/null differ diff --git a/tests/uploads/fixture/PNG b/tests/uploads/fixture/PNG deleted file mode 100644 index 5514ad40e9..0000000000 Binary files a/tests/uploads/fixture/PNG and /dev/null differ diff --git a/tests/uploads/fixture/TIF b/tests/uploads/fixture/TIF deleted file mode 100644 index 248b50f9cb..0000000000 Binary files a/tests/uploads/fixture/TIF and /dev/null differ diff --git a/tests/uploads/fixture/TXT b/tests/uploads/fixture/TXT deleted file mode 100644 index d3c40d2ea7..0000000000 --- a/tests/uploads/fixture/TXT +++ /dev/null @@ -1 +0,0 @@ -mime trigger diff --git a/tests/uploads/fixture/gif b/tests/uploads/fixture/gif new file mode 100644 index 0000000000..b636f4b8df Binary files /dev/null and b/tests/uploads/fixture/gif differ diff --git a/tests/uploads/fixture/jpg b/tests/uploads/fixture/jpg new file mode 100644 index 0000000000..3cd5038e38 Binary files /dev/null and b/tests/uploads/fixture/jpg differ diff --git a/tests/uploads/fixture/png b/tests/uploads/fixture/png new file mode 100644 index 0000000000..5514ad40e9 Binary files /dev/null and b/tests/uploads/fixture/png differ diff --git a/tests/uploads/fixture/tif b/tests/uploads/fixture/tif new file mode 100644 index 0000000000..248b50f9cb Binary files /dev/null and b/tests/uploads/fixture/tif differ diff --git a/tests/uploads/fixture/txt b/tests/uploads/fixture/txt new file mode 100644 index 0000000000..d3c40d2ea7 --- /dev/null +++ b/tests/uploads/fixture/txt @@ -0,0 +1 @@ +mime trigger -- cgit v1.2.1 From f2bbbdaaface8ca63a3a70e98140c0e51c5e8b0b Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 2 Jul 2012 22:36:12 +0100 Subject: [ticket/10941] tearDown() now uses explicit file list Instances of $it also renamed for clarity. PHPBB3-10941 --- tests/uploads/filespec_test.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/uploads/filespec_test.php b/tests/uploads/filespec_test.php index 3c9eda4468..80237d7622 100644 --- a/tests/uploads/filespec_test.php +++ b/tests/uploads/filespec_test.php @@ -43,8 +43,8 @@ class phpbb_filespec_test extends phpbb_test_case $this->init_filespec(); // Create copies of the files for use in testing move_file - $it = new DirectoryIterator($this->path); - foreach ($it as $fileinfo) + $iterator = new DirectoryIterator($this->path); + foreach ($iterator as $fileinfo) { if ($fileinfo->isDot()) { @@ -142,10 +142,24 @@ class phpbb_filespec_test extends phpbb_test_case protected function tearDown() { - $it = new DirectoryIterator($this->path); - foreach ($it as $fileinfo) + $files = array( + 'gif_copy' => 1, + 'jpg_copy' => 1, + 'png_copy' => 1, + 'txt_copy' => 1, + 'txt_copy_2' => 1, + 'tif_copy' => 1, + 'gif_moved' => 1, + 'jpg_moved' => 1, + 'png_moved' => 1, + 'txt_as_img' => 1, + 'txt_moved' => 1, + ); + + $iterator = new DirectoryIterator($this->path); + foreach ($iterator as $fileinfo) { - if (strlen($fileinfo->getFilename()) > 3) + if (isset($files[$fileinfo->getFilename()])) { unlink($fileinfo->getPathname()); } -- cgit v1.2.1 From 59a7b10f1471ccd652d152578b6d027dcbc3fa7f Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 2 Jul 2012 22:44:33 +0100 Subject: [ticket/10941] Added a comment explaining the incomplete test PHPBB3-10941 --- tests/functional/fileupload_test.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/functional/fileupload_test.php b/tests/functional/fileupload_test.php index bbcc0c37c9..1c40041cc5 100644 --- a/tests/functional/fileupload_test.php +++ b/tests/functional/fileupload_test.php @@ -14,7 +14,13 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case { public function test_form_upload() { + // This test is marked as incomplete due to an apparent bug in the + // symfony framework which causes it to lose the mimetype of any file + // uploaded. Since filespec::is_image() relies on the mimetype, all + // image uploads fail. filespec::is_image() is fixed in: + // https://github.com/phpbb/phpbb3/pull/833 $this->markTestIncomplete(); + $path = __DIR__ . '/fixtures/files/'; $this->add_lang('posting'); $this->login(); -- cgit v1.2.1 From 943af957e6b6e765269294b0b24a82b68766f3ba Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 2 Jul 2012 22:55:15 +0100 Subject: [ticket/10941] Re-arranged dataProvidor methods to be near their callers PHPBB3-10941 --- tests/uploads/filespec_test.php | 134 ++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 67 deletions(-) (limited to 'tests') diff --git a/tests/uploads/filespec_test.php b/tests/uploads/filespec_test.php index 80237d7622..3d90f51f3b 100644 --- a/tests/uploads/filespec_test.php +++ b/tests/uploads/filespec_test.php @@ -59,50 +59,6 @@ class phpbb_filespec_test extends phpbb_test_case } } - public function additional_checks_variables() - { - return array( - array('gif', true), - array('jpg', false), - array('png', true), - array('tif', false), - array('txt', true), - ); - } - - public function check_content_variables() - { - return array( - array('gif', true), - array('jpg', true), - array('png', true), - array('tif', true), - array('txt', false), - ); - } - - public function clean_filename_variables() - { - $chunks = str_split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\'\\" /:*?<>|[];(){},#+=-_`', 8); - return array( - array($chunks[0] . $chunks[7]), - array($chunks[1] . $chunks[8]), - array($chunks[2] . $chunks[9]), - array($chunks[3] . $chunks[4]), - array($chunks[5] . $chunks[6]), - ); - } - - public function get_extension_variables() - { - return array( - array('file.png', 'png'), - array('file.phpbb.gif', 'gif'), - array('file..', ''), - array('.file..jpg.webp', 'webp'), - ); - } - private function init_filespec($override = array()) { // Initialise a blank filespec object for use with trivial methods @@ -117,29 +73,6 @@ class phpbb_filespec_test extends phpbb_test_case $this->filespec = new filespec(array_merge($upload_ary, $override), null); } - public function is_image_variables() - { - return array( - array('gif', 'image/gif', true), - array('jpg', 'image/jpg', true), - array('png', 'image/png', true), - array('tif', 'image/tif', true), - array('txt', 'text/plain', false), - ); - } - - public function move_file_variables() - { - return array( - array('gif_copy', 'gif_moved', 'image/gif', 'gif', false, true), - array('non_existant', 'still_non_existant', 'text/plain', 'txt', true, false), - array('txt_copy', 'txt_as_img', 'image/jpg', 'txt', true, true), - array('txt_copy_2', 'txt_moved', 'text/plain', 'txt', false, true), - array('jpg_copy', 'jpg_moved', 'image/png', 'jpg', false, true), - array('png_copy', 'png_moved', 'image/png', 'jpg', true, true), - ); - } - protected function tearDown() { $files = array( @@ -168,6 +101,17 @@ class phpbb_filespec_test extends phpbb_test_case $this->config = array(); } + public function additional_checks_variables() + { + return array( + array('gif', true), + array('jpg', false), + array('png', true), + array('tif', false), + array('txt', true), + ); + } + /** * @dataProvider additional_checks_variables */ @@ -188,6 +132,17 @@ class phpbb_filespec_test extends phpbb_test_case $user = null; } + public function check_content_variables() + { + return array( + array('gif', true), + array('jpg', true), + array('png', true), + array('tif', true), + array('txt', false), + ); + } + /** * @dataProvider check_content_variables */ @@ -198,6 +153,18 @@ class phpbb_filespec_test extends phpbb_test_case $this->assertEquals($expected, $this->filespec->check_content($disallowed_content)); } + public function clean_filename_variables() + { + $chunks = str_split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\'\\" /:*?<>|[];(){},#+=-_`', 8); + return array( + array($chunks[0] . $chunks[7]), + array($chunks[1] . $chunks[8]), + array($chunks[2] . $chunks[9]), + array($chunks[3] . $chunks[4]), + array($chunks[5] . $chunks[6]), + ); + } + /** * @dataProvider clean_filename_variables */ @@ -232,6 +199,16 @@ class phpbb_filespec_test extends phpbb_test_case } } + public function get_extension_variables() + { + return array( + array('file.png', 'png'), + array('file.phpbb.gif', 'gif'), + array('file..', ''), + array('.file..jpg.webp', 'webp'), + ); + } + /** * @dataProvider get_extension_variables */ @@ -240,6 +217,17 @@ class phpbb_filespec_test extends phpbb_test_case $this->assertEquals($expected, $this->filespec->get_extension($filename)); } + public function is_image_variables() + { + return array( + array('gif', 'image/gif', true), + array('jpg', 'image/jpg', true), + array('png', 'image/png', true), + array('tif', 'image/tif', true), + array('txt', 'text/plain', false), + ); + } + /** * @dataProvider is_image_variables */ @@ -249,6 +237,18 @@ class phpbb_filespec_test extends phpbb_test_case $this->assertEquals($expected, $this->filespec->is_image()); } + public function move_file_variables() + { + return array( + array('gif_copy', 'gif_moved', 'image/gif', 'gif', false, true), + array('non_existant', 'still_non_existant', 'text/plain', 'txt', true, false), + array('txt_copy', 'txt_as_img', 'image/jpg', 'txt', true, true), + array('txt_copy_2', 'txt_moved', 'text/plain', 'txt', false, true), + array('jpg_copy', 'jpg_moved', 'image/png', 'jpg', false, true), + array('png_copy', 'png_moved', 'image/png', 'jpg', true, true), + ); + } + /** * @dataProvider move_file_variables */ -- cgit v1.2.1 From 19405a7f47ea6d63eaf1cde3053c6b158c7b4dba Mon Sep 17 00:00:00 2001 From: Fyorl Date: Tue, 3 Jul 2012 00:32:50 +0100 Subject: [ticket/10941] Now actually checks for the value of errors. Uses phpbb_mock_lang to return the key used when setting errors to allow that key to be checked for during tests rather than just checking if any error was set. PHPBB3-10941 --- tests/functional/fileupload_test.php | 17 +++++++++-------- tests/uploads/filespec_test.php | 26 ++++++++++++++++---------- tests/uploads/fileupload_test.php | 11 ++++------- 3 files changed, 29 insertions(+), 25 deletions(-) (limited to 'tests') diff --git a/tests/functional/fileupload_test.php b/tests/functional/fileupload_test.php index 1c40041cc5..ee89836c45 100644 --- a/tests/functional/fileupload_test.php +++ b/tests/functional/fileupload_test.php @@ -57,15 +57,12 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case public function test_remote_upload() { - // Note: we cannot check for the actual value of the error messages - // since they are passed through the translator which will result in - // blank strings within this test framework. - // Only doing this within the functional framework because we need a // URL // Global $config required by unique_id - global $config; + // Global $user required by fileupload::remote_upload + global $config, $user; if (!is_array($config)) { @@ -75,20 +72,23 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case $config['rand_seed'] = ''; $config['rand_seed_last_update'] = time() + 600; + $user = new phpbb_mock_user(); + $user->lang = new phpbb_mock_lang(); + // Test 1: Invalid extension $upload = new fileupload('', array('jpg'), 100); $file = $upload->remote_upload('http://example.com/image.gif'); - $this->assertEquals(1, sizeof($file->error)); + $this->assertEquals('URL_INVALID',$file->error[0]); // Test 2: Non-existant file $upload = new fileupload('', array('jpg'), 100); $file = $upload->remote_upload('http://example.com/image.jpg'); - $this->assertEquals(1, sizeof($file->error)); + $this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]); // Test 3: File too large $upload = new fileupload('', array('gif'), 100); $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); - $this->assertEquals(1, sizeof($file->error)); + $this->assertEquals('WRONG_FILESIZE', $file->error[0]); // Test 4: Successful upload $upload = new fileupload('', array('gif'), 1000); @@ -97,5 +97,6 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case $this->assertTrue(file_exists($file->filename)); $config = array(); + $user = null; } } diff --git a/tests/uploads/filespec_test.php b/tests/uploads/filespec_test.php index 3d90f51f3b..7ad244aa27 100644 --- a/tests/uploads/filespec_test.php +++ b/tests/uploads/filespec_test.php @@ -27,7 +27,9 @@ class phpbb_filespec_test extends phpbb_test_case protected function setUp() { // Global $config required by unique_id - global $config; + // Global $user required by filespec::additional_checks and + // filespec::move_file + global $config, $user; if (!is_array($config)) { @@ -38,6 +40,9 @@ class phpbb_filespec_test extends phpbb_test_case $config['rand_seed_last_update'] = time() + 600; $config['mime_triggers'] = 'body|head|html|img|plaintext|a href|pre|script|table|title'; + $user = new phpbb_mock_user(); + $user->lang = new phpbb_mock_lang(); + $this->config = &$config; $this->path = __DIR__ . '/fixture/'; $this->init_filespec(); @@ -75,6 +80,8 @@ class phpbb_filespec_test extends phpbb_test_case protected function tearDown() { + global $user; + $files = array( 'gif_copy' => 1, 'jpg_copy' => 1, @@ -99,6 +106,7 @@ class phpbb_filespec_test extends phpbb_test_case } $this->config = array(); + $user = null; } public function additional_checks_variables() @@ -117,10 +125,6 @@ class phpbb_filespec_test extends phpbb_test_case */ public function test_additional_checks($filename, $expected) { - // Global $user required by filespec::additional_checks - global $user; - $user = new phpbb_mock_user(); - $upload = new phpbb_mock_fileupload(); $this->init_filespec(array('tmp_name', $this->path . $filename)); $this->filespec->upload = $upload; @@ -170,7 +174,6 @@ class phpbb_filespec_test extends phpbb_test_case */ public function test_clean_filename_real($filename) { - $bad_chars = array("'", "\\", ' ', '/', ':', '*', '?', '"', '<', '>', '|'); $this->init_filespec(array('name' => $filename)); $this->filespec->clean_filename('real', self::PREFIX); @@ -241,11 +244,11 @@ class phpbb_filespec_test extends phpbb_test_case { return array( array('gif_copy', 'gif_moved', 'image/gif', 'gif', false, true), - array('non_existant', 'still_non_existant', 'text/plain', 'txt', true, false), - array('txt_copy', 'txt_as_img', 'image/jpg', 'txt', true, true), + array('non_existant', 'still_non_existant', 'text/plain', 'txt', 'GENERAL_UPLOAD_ERROR', false), + array('txt_copy', 'txt_as_img', 'image/jpg', 'txt', 'UNABLE_GET_IMAGE_SIZE', true), array('txt_copy_2', 'txt_moved', 'text/plain', 'txt', false, true), array('jpg_copy', 'jpg_moved', 'image/png', 'jpg', false, true), - array('png_copy', 'png_moved', 'image/png', 'jpg', true, true), + array('png_copy', 'png_moved', 'image/png', 'jpg', 'IMAGE_FILETYPE_MISMATCH', true), ); } @@ -272,8 +275,11 @@ class phpbb_filespec_test extends phpbb_test_case $this->filespec->local = true; $this->assertEquals($expected, $this->filespec->move_file($this->path)); - $this->assertEquals($error, (bool) sizeof($this->filespec->error)); $this->assertEquals($this->filespec->file_moved, file_exists($this->path . $realname)); + if ($error) + { + $this->assertEquals($error, $this->filespec->error[0]); + } $phpEx = ''; } diff --git a/tests/uploads/fileupload_test.php b/tests/uploads/fileupload_test.php index cb346fd0a2..d5cd3d891b 100644 --- a/tests/uploads/fileupload_test.php +++ b/tests/uploads/fileupload_test.php @@ -31,6 +31,7 @@ class phpbb_fileupload_test extends phpbb_test_case $config['rand_seed_last_update'] = time() + 600; $user = new phpbb_mock_user(); + $user->lang = new phpbb_mock_lang(); $this->path = __DIR__ . '/fixture/'; } @@ -56,10 +57,6 @@ class phpbb_fileupload_test extends phpbb_test_case public function test_common_checks() { - // Note: we cannot check for the actual value of the error messages - // since they are passed through the translator which will result in - // blank strings within this test framework. - // Test 1: Valid file $upload = new fileupload('', array('jpg'), 1000); $file = $this->gen_valid_filespec(); @@ -71,20 +68,20 @@ class phpbb_fileupload_test extends phpbb_test_case $file = $this->gen_valid_filespec(); $file->filesize = 1000; $upload->common_checks($file); - $this->assertEquals(1, sizeof($file->error)); + $this->assertEquals('WRONG_FILESIZE', $file->error[0]); // Test 3: Invalid filename $upload = new fileupload('', array('jpg'), 100); $file = $this->gen_valid_filespec(); $file->realname = 'invalid?'; $upload->common_checks($file); - $this->assertEquals(1, sizeof($file->error)); + $this->assertEquals('INVALID_FILENAME', $file->error[0]); // Test 4: Invalid extension $upload = new fileupload('', array('png'), 100); $file = $this->gen_valid_filespec(); $upload->common_checks($file); - $this->assertEquals(1, sizeof($file->error)); + $this->assertEquals('DISALLOWED_EXTENSION', $file->error[0]); } public function test_local_upload() -- cgit v1.2.1 From 1bb64ab23eb7ed4062c720958ffdf18781177b51 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Tue, 3 Jul 2012 00:39:24 +0100 Subject: [ticket/10941] Changed assertTrue to assertEquals PHPBB3-10941 --- tests/uploads/filespec_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/uploads/filespec_test.php b/tests/uploads/filespec_test.php index 7ad244aa27..f606e58c00 100644 --- a/tests/uploads/filespec_test.php +++ b/tests/uploads/filespec_test.php @@ -195,7 +195,7 @@ class phpbb_filespec_test extends phpbb_test_case $this->filespec->clean_filename('unique', self::PREFIX); $name = $this->filespec->realname; - $this->assertTrue(strlen($name) === 32 + strlen(self::PREFIX)); + $this->assertEquals(strlen($name), 32 + strlen(self::PREFIX)); $this->assertRegExp('#^[A-Za-z0-9]+$#', substr($name, strlen(self::PREFIX))); $this->assertFalse(isset($filenames[$name])); $filenames[$name] = true; -- cgit v1.2.1 From 61d74007a4b728f67c672561a8dd907e64de3070 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Tue, 3 Jul 2012 02:03:26 +0100 Subject: [ticket/10941] Minor typo fixes Removed superfluous $user = null; that was left over from refactoring. PHPBB3-10941 --- tests/functional/fileupload_test.php | 2 +- tests/uploads/filespec_test.php | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/functional/fileupload_test.php b/tests/functional/fileupload_test.php index ee89836c45..44bb22da8f 100644 --- a/tests/functional/fileupload_test.php +++ b/tests/functional/fileupload_test.php @@ -78,7 +78,7 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case // Test 1: Invalid extension $upload = new fileupload('', array('jpg'), 100); $file = $upload->remote_upload('http://example.com/image.gif'); - $this->assertEquals('URL_INVALID',$file->error[0]); + $this->assertEquals('URL_INVALID', $file->error[0]); // Test 2: Non-existant file $upload = new fileupload('', array('jpg'), 100); diff --git a/tests/uploads/filespec_test.php b/tests/uploads/filespec_test.php index f606e58c00..d84f8d431c 100644 --- a/tests/uploads/filespec_test.php +++ b/tests/uploads/filespec_test.php @@ -132,8 +132,6 @@ class phpbb_filespec_test extends phpbb_test_case $this->filespec->filesize = $this->filespec->get_filesize($this->path . $filename); $this->assertEquals($expected, $this->filespec->additional_checks()); - - $user = null; } public function check_content_variables() -- cgit v1.2.1 From ff7e5d73f767b756078f0966ea955a2d57a26988 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Tue, 3 Jul 2012 02:22:19 +0100 Subject: [ticket/10941] Refactored init_filespec to return new object. Removed $filespec as a property of the filespec test and instead just instantiate new objects. PHPBB3-10941 --- tests/uploads/filespec_test.php | 53 ++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 27 deletions(-) (limited to 'tests') diff --git a/tests/uploads/filespec_test.php b/tests/uploads/filespec_test.php index d84f8d431c..0fc666f992 100644 --- a/tests/uploads/filespec_test.php +++ b/tests/uploads/filespec_test.php @@ -21,7 +21,6 @@ class phpbb_filespec_test extends phpbb_test_case const UPLOAD_MAX_FILESIZE = 1000; private $config; - private $filespec; public $path; protected function setUp() @@ -45,7 +44,6 @@ class phpbb_filespec_test extends phpbb_test_case $this->config = &$config; $this->path = __DIR__ . '/fixture/'; - $this->init_filespec(); // Create copies of the files for use in testing move_file $iterator = new DirectoryIterator($this->path); @@ -64,7 +62,7 @@ class phpbb_filespec_test extends phpbb_test_case } } - private function init_filespec($override = array()) + private function get_filespec($override = array()) { // Initialise a blank filespec object for use with trivial methods $upload_ary = array( @@ -75,7 +73,7 @@ class phpbb_filespec_test extends phpbb_test_case 'error' => '', ); - $this->filespec = new filespec(array_merge($upload_ary, $override), null); + return new filespec(array_merge($upload_ary, $override), null); } protected function tearDown() @@ -126,12 +124,12 @@ class phpbb_filespec_test extends phpbb_test_case public function test_additional_checks($filename, $expected) { $upload = new phpbb_mock_fileupload(); - $this->init_filespec(array('tmp_name', $this->path . $filename)); - $this->filespec->upload = $upload; - $this->filespec->file_moved = true; - $this->filespec->filesize = $this->filespec->get_filesize($this->path . $filename); + $filespec = $this->get_filespec(array('tmp_name', $this->path . $filename)); + $filespec->upload = $upload; + $filespec->file_moved = true; + $filespec->filesize = $filespec->get_filesize($this->path . $filename); - $this->assertEquals($expected, $this->filespec->additional_checks()); + $this->assertEquals($expected, $filespec->additional_checks()); } public function check_content_variables() @@ -151,8 +149,8 @@ class phpbb_filespec_test extends phpbb_test_case public function test_check_content($filename, $expected) { $disallowed_content = explode('|', $this->config['mime_triggers']); - $this->init_filespec(array('tmp_name' => $this->path . $filename)); - $this->assertEquals($expected, $this->filespec->check_content($disallowed_content)); + $filespec = $this->get_filespec(array('tmp_name' => $this->path . $filename)); + $this->assertEquals($expected, $filespec->check_content($disallowed_content)); } public function clean_filename_variables() @@ -173,9 +171,9 @@ class phpbb_filespec_test extends phpbb_test_case public function test_clean_filename_real($filename) { $bad_chars = array("'", "\\", ' ', '/', ':', '*', '?', '"', '<', '>', '|'); - $this->init_filespec(array('name' => $filename)); - $this->filespec->clean_filename('real', self::PREFIX); - $name = $this->filespec->realname; + $filespec = $this->get_filespec(array('name' => $filename)); + $filespec->clean_filename('real', self::PREFIX); + $name = $filespec->realname; $this->assertEquals(0, preg_match('/%(\w{2})/', $name)); foreach ($bad_chars as $char) @@ -189,9 +187,9 @@ class phpbb_filespec_test extends phpbb_test_case $filenames = array(); for ($tests = 0; $tests < self::TEST_COUNT; $tests++) { - $this->init_filespec(); - $this->filespec->clean_filename('unique', self::PREFIX); - $name = $this->filespec->realname; + $filespec = $this->get_filespec(); + $filespec->clean_filename('unique', self::PREFIX); + $name = $filespec->realname; $this->assertEquals(strlen($name), 32 + strlen(self::PREFIX)); $this->assertRegExp('#^[A-Za-z0-9]+$#', substr($name, strlen(self::PREFIX))); @@ -215,7 +213,8 @@ class phpbb_filespec_test extends phpbb_test_case */ public function test_get_extension($filename, $expected) { - $this->assertEquals($expected, $this->filespec->get_extension($filename)); + $filespec = $this->get_filespec(); + $this->assertEquals($expected, $filespec->get_extension($filename)); } public function is_image_variables() @@ -234,8 +233,8 @@ class phpbb_filespec_test extends phpbb_test_case */ public function test_is_image($filename, $mimetype, $expected) { - $this->init_filespec(array('tmp_name' => $this->path . $filename, 'type' => $mimetype)); - $this->assertEquals($expected, $this->filespec->is_image()); + $filespec = $this->get_filespec(array('tmp_name' => $this->path . $filename, 'type' => $mimetype)); + $this->assertEquals($expected, $filespec->is_image()); } public function move_file_variables() @@ -263,20 +262,20 @@ class phpbb_filespec_test extends phpbb_test_case $upload = new phpbb_mock_fileupload(); $upload->max_filesize = self::UPLOAD_MAX_FILESIZE; - $this->init_filespec(array( + $filespec = $this->get_filespec(array( 'tmp_name' => $this->path . $tmp_name, 'name' => $realname, 'type' => $mime_type, )); - $this->filespec->extension = $extension; - $this->filespec->upload = $upload; - $this->filespec->local = true; + $filespec->extension = $extension; + $filespec->upload = $upload; + $filespec->local = true; - $this->assertEquals($expected, $this->filespec->move_file($this->path)); - $this->assertEquals($this->filespec->file_moved, file_exists($this->path . $realname)); + $this->assertEquals($expected, $filespec->move_file($this->path)); + $this->assertEquals($filespec->file_moved, file_exists($this->path . $realname)); if ($error) { - $this->assertEquals($error, $this->filespec->error[0]); + $this->assertEquals($error, $filespec->error[0]); } $phpEx = ''; -- cgit v1.2.1 From 682757c1cb1b7d7c8e438de374a790049a11164e Mon Sep 17 00:00:00 2001 From: Fyorl Date: Tue, 3 Jul 2012 02:28:49 +0100 Subject: [ticket/10941] Refactored tearDown to stop iterating over the directory. PHPBB3-10941 --- tests/uploads/filespec_test.php | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'tests') diff --git a/tests/uploads/filespec_test.php b/tests/uploads/filespec_test.php index 0fc666f992..e91819142a 100644 --- a/tests/uploads/filespec_test.php +++ b/tests/uploads/filespec_test.php @@ -79,32 +79,27 @@ class phpbb_filespec_test extends phpbb_test_case protected function tearDown() { global $user; + $this->config = array(); + $user = null; $files = array( - 'gif_copy' => 1, - 'jpg_copy' => 1, - 'png_copy' => 1, - 'txt_copy' => 1, - 'txt_copy_2' => 1, - 'tif_copy' => 1, - 'gif_moved' => 1, - 'jpg_moved' => 1, - 'png_moved' => 1, - 'txt_as_img' => 1, - 'txt_moved' => 1, + 'gif_copy', + 'jpg_copy', + 'png_copy', + 'txt_copy', + 'txt_copy_2', + 'tif_copy', + 'gif_moved', + 'jpg_moved', + 'png_moved', + 'txt_as_img', + 'txt_moved', ); - $iterator = new DirectoryIterator($this->path); - foreach ($iterator as $fileinfo) + foreach ($files as $file) { - if (isset($files[$fileinfo->getFilename()])) - { - unlink($fileinfo->getPathname()); - } + @unlink($this->path . $file); } - - $this->config = array(); - $user = null; } public function additional_checks_variables() -- cgit v1.2.1 From a4717ef525969427aac77eb077f28ee2d587126c Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sun, 8 Jul 2012 00:46:09 +0100 Subject: [ticket/10941] Removed the incomplete mark as is_image is fixed Had to remove one of the tests due to a small limitation with the functional testing framework. May mark the test as incomplete again pending further comments. PHPBB3-10941 --- tests/functional/fileupload_test.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/functional/fileupload_test.php b/tests/functional/fileupload_test.php index 44bb22da8f..2abf81c457 100644 --- a/tests/functional/fileupload_test.php +++ b/tests/functional/fileupload_test.php @@ -14,13 +14,6 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case { public function test_form_upload() { - // This test is marked as incomplete due to an apparent bug in the - // symfony framework which causes it to lose the mimetype of any file - // uploaded. Since filespec::is_image() relies on the mimetype, all - // image uploads fail. filespec::is_image() is fixed in: - // https://github.com/phpbb/phpbb3/pull/833 - $this->markTestIncomplete(); - $path = __DIR__ . '/fixtures/files/'; $this->add_lang('posting'); $this->login(); @@ -30,21 +23,23 @@ class phpbb_functional_fileupload_test extends phpbb_functional_test_case $form = $crawler->selectButton('add_file')->form(); $form['fileupload']->upload($path . 'illegal-extension.bif'); $crawler = $this->client->submit($form); - $this->assertEquals(1, $crawler->filter('p.error')->count()); + $this->assertEquals('The extension bif is not allowed.', $crawler->filter('p.error')->text()); // Test 2: Empty file $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); $form = $crawler->selectButton('add_file')->form(); $form['fileupload']->upload($path . 'empty.png'); $crawler = $this->client->submit($form); - $this->assertEquals(1, $crawler->filter('p.error')->count()); + $this->assertEquals('The image file you tried to attach is invalid.', $crawler->filter('div#message p')->text()); // Test 3: File too large - $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + // Cannot be tested by an admin account which this functional framework + // provides + /*$crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); $form = $crawler->selectButton('add_file')->form(); $form['fileupload']->upload($path . 'too-large.png'); $crawler = $this->client->submit($form); - $this->assertEquals(1, $crawler->filter('div#message')->count()); + $this->assertEquals(1, $crawler->filter('div#message')->count());*/ // Test 4: Valid file $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); -- cgit v1.2.1 From b65f08dd95de07405ed7f19fd980ca7d09925406 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sun, 8 Jul 2012 01:22:26 +0100 Subject: [ticket/10941] Rearranged tests into their own classes or methods PHPBB3-10941 --- tests/functional/fileupload_test.php | 97 ----------------------------- tests/functional/fileupload_test_form.php | 62 ++++++++++++++++++ tests/functional/fileupload_test_remote.php | 71 +++++++++++++++++++++ tests/uploads/fileupload_test.php | 31 +++++---- 4 files changed, 151 insertions(+), 110 deletions(-) delete mode 100644 tests/functional/fileupload_test.php create mode 100644 tests/functional/fileupload_test_form.php create mode 100644 tests/functional/fileupload_test_remote.php (limited to 'tests') diff --git a/tests/functional/fileupload_test.php b/tests/functional/fileupload_test.php deleted file mode 100644 index 2abf81c457..0000000000 --- a/tests/functional/fileupload_test.php +++ /dev/null @@ -1,97 +0,0 @@ -add_lang('posting'); - $this->login(); - - // Test 1: Invalid extension - $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); - $form = $crawler->selectButton('add_file')->form(); - $form['fileupload']->upload($path . 'illegal-extension.bif'); - $crawler = $this->client->submit($form); - $this->assertEquals('The extension bif is not allowed.', $crawler->filter('p.error')->text()); - - // Test 2: Empty file - $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); - $form = $crawler->selectButton('add_file')->form(); - $form['fileupload']->upload($path . 'empty.png'); - $crawler = $this->client->submit($form); - $this->assertEquals('The image file you tried to attach is invalid.', $crawler->filter('div#message p')->text()); - - // Test 3: File too large - // Cannot be tested by an admin account which this functional framework - // provides - /*$crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); - $form = $crawler->selectButton('add_file')->form(); - $form['fileupload']->upload($path . 'too-large.png'); - $crawler = $this->client->submit($form); - $this->assertEquals(1, $crawler->filter('div#message')->count());*/ - - // Test 4: Valid file - $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); - $form = $crawler->selectButton('add_file')->form(); - $form['fileupload']->upload($path . 'valid.jpg'); - $crawler = $this->client->submit($form); - $this->assertEquals(0, $crawler->filter('p.error')->count()); - $this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->eq(1)->text()); - } - - public function test_remote_upload() - { - // Only doing this within the functional framework because we need a - // URL - - // Global $config required by unique_id - // Global $user required by fileupload::remote_upload - global $config, $user; - - if (!is_array($config)) - { - $config = array(); - } - - $config['rand_seed'] = ''; - $config['rand_seed_last_update'] = time() + 600; - - $user = new phpbb_mock_user(); - $user->lang = new phpbb_mock_lang(); - - // Test 1: Invalid extension - $upload = new fileupload('', array('jpg'), 100); - $file = $upload->remote_upload('http://example.com/image.gif'); - $this->assertEquals('URL_INVALID', $file->error[0]); - - // Test 2: Non-existant file - $upload = new fileupload('', array('jpg'), 100); - $file = $upload->remote_upload('http://example.com/image.jpg'); - $this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]); - - // Test 3: File too large - $upload = new fileupload('', array('gif'), 100); - $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); - $this->assertEquals('WRONG_FILESIZE', $file->error[0]); - - // Test 4: Successful upload - $upload = new fileupload('', array('gif'), 1000); - $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); - $this->assertEquals(0, sizeof($file->error)); - $this->assertTrue(file_exists($file->filename)); - - $config = array(); - $user = null; - } -} diff --git a/tests/functional/fileupload_test_form.php b/tests/functional/fileupload_test_form.php new file mode 100644 index 0000000000..48fa75ca4b --- /dev/null +++ b/tests/functional/fileupload_test_form.php @@ -0,0 +1,62 @@ +path = __DIR__ . '/fixtures/files/'; + $this->add_lang('posting'); + $this->login(); + } + + public function test_empty_file() + { + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($this->path . 'empty.png'); + $crawler = $this->client->submit($form); + $this->assertEquals('The image file you tried to attach is invalid.', $crawler->filter('div#message p')->text()); + } + + public function test_invalid_extension() + { + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($this->path . 'illegal-extension.bif'); + $crawler = $this->client->submit($form); + $this->assertEquals('The extension bif is not allowed.', $crawler->filter('p.error')->text()); + } + + public function test_too_large() + { + // Cannot be tested by an admin account which this functional framework + // provides + /*$crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($path . 'too-large.png'); + $crawler = $this->client->submit($form); + $this->assertEquals(1, $crawler->filter('div#message')->count());*/ + } + + public function test_valid_file() + { + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($this->path . 'valid.jpg'); + $crawler = $this->client->submit($form); + $this->assertEquals(0, $crawler->filter('p.error')->count()); + $this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->eq(1)->text()); + } +} diff --git a/tests/functional/fileupload_test_remote.php b/tests/functional/fileupload_test_remote.php new file mode 100644 index 0000000000..ac55a078d4 --- /dev/null +++ b/tests/functional/fileupload_test_remote.php @@ -0,0 +1,71 @@ +lang = new phpbb_mock_lang(); + } + + protected function tearDown() + { + global $config, $user; + $user = null; + $config = array(); + } + + public function test_invalid_extension() + { + $upload = new fileupload('', array('jpg'), 100); + $file = $upload->remote_upload('http://example.com/image.gif'); + $this->assertEquals('URL_INVALID', $file->error[0]); + } + + public function test_non_existant() + { + $upload = new fileupload('', array('jpg'), 100); + $file = $upload->remote_upload('http://example.com/image.jpg'); + $this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]); + } + + public function test_successful_upload() + { + $upload = new fileupload('', array('gif'), 1000); + $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $this->assertEquals(0, sizeof($file->error)); + $this->assertTrue(file_exists($file->filename)); + } + + public function test_too_large() + { + $upload = new fileupload('', array('gif'), 100); + $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $this->assertEquals('WRONG_FILESIZE', $file->error[0]); + } +} diff --git a/tests/uploads/fileupload_test.php b/tests/uploads/fileupload_test.php index d5cd3d891b..2b3c17b8e0 100644 --- a/tests/uploads/fileupload_test.php +++ b/tests/uploads/fileupload_test.php @@ -55,33 +55,38 @@ class phpbb_fileupload_test extends phpbb_test_case $user = null; } - public function test_common_checks() + public function test_common_checks_invalid_extension() { - // Test 1: Valid file - $upload = new fileupload('', array('jpg'), 1000); + $upload = new fileupload('', array('png'), 100); $file = $this->gen_valid_filespec(); $upload->common_checks($file); - $this->assertEquals(0, sizeof($file->error)); + $this->assertEquals('DISALLOWED_EXTENSION', $file->error[0]); + } - // Test 2: File too large + public function test_common_checks_invalid_filename() + { $upload = new fileupload('', array('jpg'), 100); $file = $this->gen_valid_filespec(); - $file->filesize = 1000; + $file->realname = 'invalid?'; $upload->common_checks($file); - $this->assertEquals('WRONG_FILESIZE', $file->error[0]); + $this->assertEquals('INVALID_FILENAME', $file->error[0]); + } - // Test 3: Invalid filename + public function test_common_checks_too_large() + { $upload = new fileupload('', array('jpg'), 100); $file = $this->gen_valid_filespec(); - $file->realname = 'invalid?'; + $file->filesize = 1000; $upload->common_checks($file); - $this->assertEquals('INVALID_FILENAME', $file->error[0]); + $this->assertEquals('WRONG_FILESIZE', $file->error[0]); + } - // Test 4: Invalid extension - $upload = new fileupload('', array('png'), 100); + public function test_common_checks_valid_file() + { + $upload = new fileupload('', array('jpg'), 1000); $file = $this->gen_valid_filespec(); $upload->common_checks($file); - $this->assertEquals('DISALLOWED_EXTENSION', $file->error[0]); + $this->assertEquals(0, sizeof($file->error)); } public function test_local_upload() -- cgit v1.2.1 From af8020b3885266a963583b465be58b557c928368 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sun, 8 Jul 2012 01:24:27 +0100 Subject: [ticket/10941] Fixed a failing test Since the is_image change, the filespec class no longer trusts the browser's reported mimetype and instead checks the file itself. Thus pretending a text file had the mimetype of an image will no longer fail, the file will simply not be treated as an image. PHPBB3-10941 --- tests/uploads/filespec_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/uploads/filespec_test.php b/tests/uploads/filespec_test.php index e91819142a..fe642ea24c 100644 --- a/tests/uploads/filespec_test.php +++ b/tests/uploads/filespec_test.php @@ -237,7 +237,7 @@ class phpbb_filespec_test extends phpbb_test_case return array( array('gif_copy', 'gif_moved', 'image/gif', 'gif', false, true), array('non_existant', 'still_non_existant', 'text/plain', 'txt', 'GENERAL_UPLOAD_ERROR', false), - array('txt_copy', 'txt_as_img', 'image/jpg', 'txt', 'UNABLE_GET_IMAGE_SIZE', true), + array('txt_copy', 'txt_as_img', 'image/jpg', 'txt', false, true), array('txt_copy_2', 'txt_moved', 'text/plain', 'txt', false, true), array('jpg_copy', 'jpg_moved', 'image/png', 'jpg', false, true), array('png_copy', 'png_moved', 'image/png', 'jpg', 'IMAGE_FILETYPE_MISMATCH', true), -- cgit v1.2.1 From d89af53f6311d9f4cec60d136cf017df9e1a36cd Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sun, 8 Jul 2012 02:15:48 +0100 Subject: [ticket/10941] Added some comments for clarification PHPBB3-10941 --- tests/mock/fileupload.php | 7 +++++++ tests/uploads/filespec_test.php | 8 ++++++++ 2 files changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/mock/fileupload.php b/tests/mock/fileupload.php index 817b090346..409036ba63 100644 --- a/tests/mock/fileupload.php +++ b/tests/mock/fileupload.php @@ -21,6 +21,13 @@ class phpbb_mock_fileupload return true; } + /** + * Copied verbatim from phpBB/includes/functions_upload.php's fileupload + * class to ensure the correct behaviour of filespec::move_file. + * + * Maps file extensions to the constant in second index of the array + * returned by getimagesize() + */ public function image_types() { return array( diff --git a/tests/uploads/filespec_test.php b/tests/uploads/filespec_test.php index fe642ea24c..c3e3ddf8f2 100644 --- a/tests/uploads/filespec_test.php +++ b/tests/uploads/filespec_test.php @@ -37,6 +37,9 @@ class phpbb_filespec_test extends phpbb_test_case $config['rand_seed'] = ''; $config['rand_seed_last_update'] = time() + 600; + // This config value is normally pulled from the database which is set + // to this value at install time. + // See: phpBB/install/schemas/schema_data.sql $config['mime_triggers'] = 'body|head|html|img|plaintext|a href|pre|script|table|title'; $user = new phpbb_mock_user(); @@ -104,6 +107,9 @@ class phpbb_filespec_test extends phpbb_test_case public function additional_checks_variables() { + // False here just indicates the file is too large and fails the + // filespec::additional_checks method because of it. All other code + // paths in that method are covered elsewhere. return array( array('gif', true), array('jpg', false), @@ -129,6 +135,8 @@ class phpbb_filespec_test extends phpbb_test_case public function check_content_variables() { + // False here indicates that a file is non-binary and contains + // disallowed content that makes IE report the mimetype incorrectly. return array( array('gif', true), array('jpg', true), -- cgit v1.2.1 From 580cec619b399f710aedc1d3c2dd92c2287ebaff Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sun, 8 Jul 2012 14:39:18 +0100 Subject: [ticket/10941] Added subdirectory for file operations Also removed common.php as it was unnecessary. PHPBB3-10941 --- tests/upload/filespec_test.php | 272 ++++++++++++++++++++++++++++++++++++ tests/upload/fileupload_test.php | 116 ++++++++++++++++ tests/upload/fixture/gif | Bin 0 -> 35 bytes tests/upload/fixture/jpg | Bin 0 -> 519 bytes tests/upload/fixture/png | Bin 0 -> 69 bytes tests/upload/fixture/tif | Bin 0 -> 256 bytes tests/upload/fixture/txt | 1 + tests/uploads/common.php | 0 tests/uploads/filespec_test.php | 286 -------------------------------------- tests/uploads/fileupload_test.php | 116 ---------------- tests/uploads/fixture/gif | Bin 35 -> 0 bytes tests/uploads/fixture/jpg | Bin 519 -> 0 bytes tests/uploads/fixture/png | Bin 69 -> 0 bytes tests/uploads/fixture/tif | Bin 256 -> 0 bytes tests/uploads/fixture/txt | 1 - 15 files changed, 389 insertions(+), 403 deletions(-) create mode 100644 tests/upload/filespec_test.php create mode 100644 tests/upload/fileupload_test.php create mode 100644 tests/upload/fixture/gif create mode 100644 tests/upload/fixture/jpg create mode 100644 tests/upload/fixture/png create mode 100644 tests/upload/fixture/tif create mode 100644 tests/upload/fixture/txt delete mode 100644 tests/uploads/common.php delete mode 100644 tests/uploads/filespec_test.php delete mode 100644 tests/uploads/fileupload_test.php delete mode 100644 tests/uploads/fixture/gif delete mode 100644 tests/uploads/fixture/jpg delete mode 100644 tests/uploads/fixture/png delete mode 100644 tests/uploads/fixture/tif delete mode 100644 tests/uploads/fixture/txt (limited to 'tests') diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php new file mode 100644 index 0000000000..7961e8ed64 --- /dev/null +++ b/tests/upload/filespec_test.php @@ -0,0 +1,272 @@ +lang = new phpbb_mock_lang(); + + $this->config = &$config; + $this->path = __DIR__ . '/fixture/'; + + // Create copies of the files for use in testing move_file + $iterator = new DirectoryIterator($this->path); + foreach ($iterator as $fileinfo) + { + if ($fileinfo->isDot() || $fileinfo->isDir()) + { + continue; + } + + copy($fileinfo->getPathname(), $this->path . 'copies/' . $fileinfo->getFilename() . '_copy'); + if ($fileinfo->getFilename() === 'txt') + { + copy($fileinfo->getPathname(), $this->path . 'copies/' . $fileinfo->getFilename() . '_copy_2'); + } + } + } + + private function get_filespec($override = array()) + { + // Initialise a blank filespec object for use with trivial methods + $upload_ary = array( + 'name' => '', + 'type' => '', + 'size' => '', + 'tmp_name' => '', + 'error' => '', + ); + + return new filespec(array_merge($upload_ary, $override), null); + } + + protected function tearDown() + { + global $user; + $this->config = array(); + $user = null; + + foreach (glob($this->path . 'copies/*') as $file) + { + unlink($file); + } + } + + public function additional_checks_variables() + { + // False here just indicates the file is too large and fails the + // filespec::additional_checks method because of it. All other code + // paths in that method are covered elsewhere. + return array( + array('gif', true), + array('jpg', false), + array('png', true), + array('tif', false), + array('txt', true), + ); + } + + /** + * @dataProvider additional_checks_variables + */ + public function test_additional_checks($filename, $expected) + { + $upload = new phpbb_mock_fileupload(); + $filespec = $this->get_filespec(array('tmp_name', $this->path . $filename)); + $filespec->upload = $upload; + $filespec->file_moved = true; + $filespec->filesize = $filespec->get_filesize($this->path . $filename); + + $this->assertEquals($expected, $filespec->additional_checks()); + } + + public function check_content_variables() + { + // False here indicates that a file is non-binary and contains + // disallowed content that makes IE report the mimetype incorrectly. + return array( + array('gif', true), + array('jpg', true), + array('png', true), + array('tif', true), + array('txt', false), + ); + } + + /** + * @dataProvider check_content_variables + */ + public function test_check_content($filename, $expected) + { + $disallowed_content = explode('|', $this->config['mime_triggers']); + $filespec = $this->get_filespec(array('tmp_name' => $this->path . $filename)); + $this->assertEquals($expected, $filespec->check_content($disallowed_content)); + } + + public function clean_filename_variables() + { + $chunks = str_split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\'\\" /:*?<>|[];(){},#+=-_`', 8); + return array( + array($chunks[0] . $chunks[7]), + array($chunks[1] . $chunks[8]), + array($chunks[2] . $chunks[9]), + array($chunks[3] . $chunks[4]), + array($chunks[5] . $chunks[6]), + ); + } + + /** + * @dataProvider clean_filename_variables + */ + public function test_clean_filename_real($filename) + { + $bad_chars = array("'", "\\", ' ', '/', ':', '*', '?', '"', '<', '>', '|'); + $filespec = $this->get_filespec(array('name' => $filename)); + $filespec->clean_filename('real', self::PREFIX); + $name = $filespec->realname; + + $this->assertEquals(0, preg_match('/%(\w{2})/', $name)); + foreach ($bad_chars as $char) + { + $this->assertFalse(strpos($name, $char)); + } + } + + public function test_clean_filename_unique() + { + $filenames = array(); + for ($tests = 0; $tests < self::TEST_COUNT; $tests++) + { + $filespec = $this->get_filespec(); + $filespec->clean_filename('unique', self::PREFIX); + $name = $filespec->realname; + + $this->assertEquals(strlen($name), 32 + strlen(self::PREFIX)); + $this->assertRegExp('#^[A-Za-z0-9]+$#', substr($name, strlen(self::PREFIX))); + $this->assertFalse(isset($filenames[$name])); + $filenames[$name] = true; + } + } + + public function get_extension_variables() + { + return array( + array('file.png', 'png'), + array('file.phpbb.gif', 'gif'), + array('file..', ''), + array('.file..jpg.webp', 'webp'), + ); + } + + /** + * @dataProvider get_extension_variables + */ + public function test_get_extension($filename, $expected) + { + $filespec = $this->get_filespec(); + $this->assertEquals($expected, $filespec->get_extension($filename)); + } + + public function is_image_variables() + { + return array( + array('gif', 'image/gif', true), + array('jpg', 'image/jpg', true), + array('png', 'image/png', true), + array('tif', 'image/tif', true), + array('txt', 'text/plain', false), + ); + } + + /** + * @dataProvider is_image_variables + */ + public function test_is_image($filename, $mimetype, $expected) + { + $filespec = $this->get_filespec(array('tmp_name' => $this->path . $filename, 'type' => $mimetype)); + $this->assertEquals($expected, $filespec->is_image()); + } + + public function move_file_variables() + { + return array( + array('gif_copy', 'gif_moved', 'image/gif', 'gif', false, true), + array('non_existant', 'still_non_existant', 'text/plain', 'txt', 'GENERAL_UPLOAD_ERROR', false), + array('txt_copy', 'txt_as_img', 'image/jpg', 'txt', false, true), + array('txt_copy_2', 'txt_moved', 'text/plain', 'txt', false, true), + array('jpg_copy', 'jpg_moved', 'image/png', 'jpg', false, true), + array('png_copy', 'png_moved', 'image/png', 'jpg', 'IMAGE_FILETYPE_MISMATCH', true), + ); + } + + /** + * @dataProvider move_file_variables + */ + public function test_move_file($tmp_name, $realname, $mime_type, $extension, $error, $expected) + { + // Global $phpbb_root_path and $phpEx are required by phpbb_chmod + global $phpbb_root_path, $phpEx; + $phpbb_root_path = ''; + $phpEx = 'php'; + + $upload = new phpbb_mock_fileupload(); + $upload->max_filesize = self::UPLOAD_MAX_FILESIZE; + + $filespec = $this->get_filespec(array( + 'tmp_name' => $this->path . 'copies/' . $tmp_name, + 'name' => $realname, + 'type' => $mime_type, + )); + $filespec->extension = $extension; + $filespec->upload = $upload; + $filespec->local = true; + + $this->assertEquals($expected, $filespec->move_file($this->path . 'copies')); + $this->assertEquals($filespec->file_moved, file_exists($this->path . 'copies/' . $realname)); + if ($error) + { + $this->assertEquals($error, $filespec->error[0]); + } + + $phpEx = ''; + } +} diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php new file mode 100644 index 0000000000..2b3c17b8e0 --- /dev/null +++ b/tests/upload/fileupload_test.php @@ -0,0 +1,116 @@ +lang = new phpbb_mock_lang(); + $this->path = __DIR__ . '/fixture/'; + } + + private function gen_valid_filespec() + { + $filespec = new phpbb_mock_filespec(); + $filespec->filesize = 1; + $filespec->extension = 'jpg'; + $filespec->realname = 'valid'; + $filespec->width = 2; + $filespec->height = 2; + + return $filespec; + } + + protected function tearDown() + { + // Clear globals + global $config, $user; + $config = array(); + $user = null; + } + + public function test_common_checks_invalid_extension() + { + $upload = new fileupload('', array('png'), 100); + $file = $this->gen_valid_filespec(); + $upload->common_checks($file); + $this->assertEquals('DISALLOWED_EXTENSION', $file->error[0]); + } + + public function test_common_checks_invalid_filename() + { + $upload = new fileupload('', array('jpg'), 100); + $file = $this->gen_valid_filespec(); + $file->realname = 'invalid?'; + $upload->common_checks($file); + $this->assertEquals('INVALID_FILENAME', $file->error[0]); + } + + public function test_common_checks_too_large() + { + $upload = new fileupload('', array('jpg'), 100); + $file = $this->gen_valid_filespec(); + $file->filesize = 1000; + $upload->common_checks($file); + $this->assertEquals('WRONG_FILESIZE', $file->error[0]); + } + + public function test_common_checks_valid_file() + { + $upload = new fileupload('', array('jpg'), 1000); + $file = $this->gen_valid_filespec(); + $upload->common_checks($file); + $this->assertEquals(0, sizeof($file->error)); + } + + public function test_local_upload() + { + $upload = new fileupload('', array('jpg'), 1000); + + copy($this->path . 'jpg', $this->path . 'jpg.jpg'); + $file = $upload->local_upload($this->path . 'jpg.jpg'); + $this->assertEquals(0, sizeof($file->error)); + unlink($this->path . 'jpg.jpg'); + } + + public function test_valid_dimensions() + { + $upload = new fileupload('', false, false, 1, 1, 100, 100); + + $file1 = $this->gen_valid_filespec(); + $file2 = $this->gen_valid_filespec(); + $file2->height = 101; + $file3 = $this->gen_valid_filespec(); + $file3->width = 0; + + $this->assertTrue($upload->valid_dimensions($file1)); + $this->assertFalse($upload->valid_dimensions($file2)); + $this->assertFalse($upload->valid_dimensions($file3)); + } +} diff --git a/tests/upload/fixture/gif b/tests/upload/fixture/gif new file mode 100644 index 0000000000..b636f4b8df Binary files /dev/null and b/tests/upload/fixture/gif differ diff --git a/tests/upload/fixture/jpg b/tests/upload/fixture/jpg new file mode 100644 index 0000000000..3cd5038e38 Binary files /dev/null and b/tests/upload/fixture/jpg differ diff --git a/tests/upload/fixture/png b/tests/upload/fixture/png new file mode 100644 index 0000000000..5514ad40e9 Binary files /dev/null and b/tests/upload/fixture/png differ diff --git a/tests/upload/fixture/tif b/tests/upload/fixture/tif new file mode 100644 index 0000000000..248b50f9cb Binary files /dev/null and b/tests/upload/fixture/tif differ diff --git a/tests/upload/fixture/txt b/tests/upload/fixture/txt new file mode 100644 index 0000000000..d3c40d2ea7 --- /dev/null +++ b/tests/upload/fixture/txt @@ -0,0 +1 @@ +mime trigger diff --git a/tests/uploads/common.php b/tests/uploads/common.php deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/uploads/filespec_test.php b/tests/uploads/filespec_test.php deleted file mode 100644 index c3e3ddf8f2..0000000000 --- a/tests/uploads/filespec_test.php +++ /dev/null @@ -1,286 +0,0 @@ -lang = new phpbb_mock_lang(); - - $this->config = &$config; - $this->path = __DIR__ . '/fixture/'; - - // Create copies of the files for use in testing move_file - $iterator = new DirectoryIterator($this->path); - foreach ($iterator as $fileinfo) - { - if ($fileinfo->isDot()) - { - continue; - } - - copy($fileinfo->getPathname(), $this->path . $fileinfo->getFilename() . '_copy'); - if ($fileinfo->getFilename() === 'txt') - { - copy($fileinfo->getPathname(), $this->path . $fileinfo->getFilename() . '_copy_2'); - } - } - } - - private function get_filespec($override = array()) - { - // Initialise a blank filespec object for use with trivial methods - $upload_ary = array( - 'name' => '', - 'type' => '', - 'size' => '', - 'tmp_name' => '', - 'error' => '', - ); - - return new filespec(array_merge($upload_ary, $override), null); - } - - protected function tearDown() - { - global $user; - $this->config = array(); - $user = null; - - $files = array( - 'gif_copy', - 'jpg_copy', - 'png_copy', - 'txt_copy', - 'txt_copy_2', - 'tif_copy', - 'gif_moved', - 'jpg_moved', - 'png_moved', - 'txt_as_img', - 'txt_moved', - ); - - foreach ($files as $file) - { - @unlink($this->path . $file); - } - } - - public function additional_checks_variables() - { - // False here just indicates the file is too large and fails the - // filespec::additional_checks method because of it. All other code - // paths in that method are covered elsewhere. - return array( - array('gif', true), - array('jpg', false), - array('png', true), - array('tif', false), - array('txt', true), - ); - } - - /** - * @dataProvider additional_checks_variables - */ - public function test_additional_checks($filename, $expected) - { - $upload = new phpbb_mock_fileupload(); - $filespec = $this->get_filespec(array('tmp_name', $this->path . $filename)); - $filespec->upload = $upload; - $filespec->file_moved = true; - $filespec->filesize = $filespec->get_filesize($this->path . $filename); - - $this->assertEquals($expected, $filespec->additional_checks()); - } - - public function check_content_variables() - { - // False here indicates that a file is non-binary and contains - // disallowed content that makes IE report the mimetype incorrectly. - return array( - array('gif', true), - array('jpg', true), - array('png', true), - array('tif', true), - array('txt', false), - ); - } - - /** - * @dataProvider check_content_variables - */ - public function test_check_content($filename, $expected) - { - $disallowed_content = explode('|', $this->config['mime_triggers']); - $filespec = $this->get_filespec(array('tmp_name' => $this->path . $filename)); - $this->assertEquals($expected, $filespec->check_content($disallowed_content)); - } - - public function clean_filename_variables() - { - $chunks = str_split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\'\\" /:*?<>|[];(){},#+=-_`', 8); - return array( - array($chunks[0] . $chunks[7]), - array($chunks[1] . $chunks[8]), - array($chunks[2] . $chunks[9]), - array($chunks[3] . $chunks[4]), - array($chunks[5] . $chunks[6]), - ); - } - - /** - * @dataProvider clean_filename_variables - */ - public function test_clean_filename_real($filename) - { - $bad_chars = array("'", "\\", ' ', '/', ':', '*', '?', '"', '<', '>', '|'); - $filespec = $this->get_filespec(array('name' => $filename)); - $filespec->clean_filename('real', self::PREFIX); - $name = $filespec->realname; - - $this->assertEquals(0, preg_match('/%(\w{2})/', $name)); - foreach ($bad_chars as $char) - { - $this->assertFalse(strpos($name, $char)); - } - } - - public function test_clean_filename_unique() - { - $filenames = array(); - for ($tests = 0; $tests < self::TEST_COUNT; $tests++) - { - $filespec = $this->get_filespec(); - $filespec->clean_filename('unique', self::PREFIX); - $name = $filespec->realname; - - $this->assertEquals(strlen($name), 32 + strlen(self::PREFIX)); - $this->assertRegExp('#^[A-Za-z0-9]+$#', substr($name, strlen(self::PREFIX))); - $this->assertFalse(isset($filenames[$name])); - $filenames[$name] = true; - } - } - - public function get_extension_variables() - { - return array( - array('file.png', 'png'), - array('file.phpbb.gif', 'gif'), - array('file..', ''), - array('.file..jpg.webp', 'webp'), - ); - } - - /** - * @dataProvider get_extension_variables - */ - public function test_get_extension($filename, $expected) - { - $filespec = $this->get_filespec(); - $this->assertEquals($expected, $filespec->get_extension($filename)); - } - - public function is_image_variables() - { - return array( - array('gif', 'image/gif', true), - array('jpg', 'image/jpg', true), - array('png', 'image/png', true), - array('tif', 'image/tif', true), - array('txt', 'text/plain', false), - ); - } - - /** - * @dataProvider is_image_variables - */ - public function test_is_image($filename, $mimetype, $expected) - { - $filespec = $this->get_filespec(array('tmp_name' => $this->path . $filename, 'type' => $mimetype)); - $this->assertEquals($expected, $filespec->is_image()); - } - - public function move_file_variables() - { - return array( - array('gif_copy', 'gif_moved', 'image/gif', 'gif', false, true), - array('non_existant', 'still_non_existant', 'text/plain', 'txt', 'GENERAL_UPLOAD_ERROR', false), - array('txt_copy', 'txt_as_img', 'image/jpg', 'txt', false, true), - array('txt_copy_2', 'txt_moved', 'text/plain', 'txt', false, true), - array('jpg_copy', 'jpg_moved', 'image/png', 'jpg', false, true), - array('png_copy', 'png_moved', 'image/png', 'jpg', 'IMAGE_FILETYPE_MISMATCH', true), - ); - } - - /** - * @dataProvider move_file_variables - */ - public function test_move_file($tmp_name, $realname, $mime_type, $extension, $error, $expected) - { - // Global $phpbb_root_path and $phpEx are required by phpbb_chmod - global $phpbb_root_path, $phpEx; - $phpbb_root_path = ''; - $phpEx = 'php'; - - $upload = new phpbb_mock_fileupload(); - $upload->max_filesize = self::UPLOAD_MAX_FILESIZE; - - $filespec = $this->get_filespec(array( - 'tmp_name' => $this->path . $tmp_name, - 'name' => $realname, - 'type' => $mime_type, - )); - $filespec->extension = $extension; - $filespec->upload = $upload; - $filespec->local = true; - - $this->assertEquals($expected, $filespec->move_file($this->path)); - $this->assertEquals($filespec->file_moved, file_exists($this->path . $realname)); - if ($error) - { - $this->assertEquals($error, $filespec->error[0]); - } - - $phpEx = ''; - } -} diff --git a/tests/uploads/fileupload_test.php b/tests/uploads/fileupload_test.php deleted file mode 100644 index 2b3c17b8e0..0000000000 --- a/tests/uploads/fileupload_test.php +++ /dev/null @@ -1,116 +0,0 @@ -lang = new phpbb_mock_lang(); - $this->path = __DIR__ . '/fixture/'; - } - - private function gen_valid_filespec() - { - $filespec = new phpbb_mock_filespec(); - $filespec->filesize = 1; - $filespec->extension = 'jpg'; - $filespec->realname = 'valid'; - $filespec->width = 2; - $filespec->height = 2; - - return $filespec; - } - - protected function tearDown() - { - // Clear globals - global $config, $user; - $config = array(); - $user = null; - } - - public function test_common_checks_invalid_extension() - { - $upload = new fileupload('', array('png'), 100); - $file = $this->gen_valid_filespec(); - $upload->common_checks($file); - $this->assertEquals('DISALLOWED_EXTENSION', $file->error[0]); - } - - public function test_common_checks_invalid_filename() - { - $upload = new fileupload('', array('jpg'), 100); - $file = $this->gen_valid_filespec(); - $file->realname = 'invalid?'; - $upload->common_checks($file); - $this->assertEquals('INVALID_FILENAME', $file->error[0]); - } - - public function test_common_checks_too_large() - { - $upload = new fileupload('', array('jpg'), 100); - $file = $this->gen_valid_filespec(); - $file->filesize = 1000; - $upload->common_checks($file); - $this->assertEquals('WRONG_FILESIZE', $file->error[0]); - } - - public function test_common_checks_valid_file() - { - $upload = new fileupload('', array('jpg'), 1000); - $file = $this->gen_valid_filespec(); - $upload->common_checks($file); - $this->assertEquals(0, sizeof($file->error)); - } - - public function test_local_upload() - { - $upload = new fileupload('', array('jpg'), 1000); - - copy($this->path . 'jpg', $this->path . 'jpg.jpg'); - $file = $upload->local_upload($this->path . 'jpg.jpg'); - $this->assertEquals(0, sizeof($file->error)); - unlink($this->path . 'jpg.jpg'); - } - - public function test_valid_dimensions() - { - $upload = new fileupload('', false, false, 1, 1, 100, 100); - - $file1 = $this->gen_valid_filespec(); - $file2 = $this->gen_valid_filespec(); - $file2->height = 101; - $file3 = $this->gen_valid_filespec(); - $file3->width = 0; - - $this->assertTrue($upload->valid_dimensions($file1)); - $this->assertFalse($upload->valid_dimensions($file2)); - $this->assertFalse($upload->valid_dimensions($file3)); - } -} diff --git a/tests/uploads/fixture/gif b/tests/uploads/fixture/gif deleted file mode 100644 index b636f4b8df..0000000000 Binary files a/tests/uploads/fixture/gif and /dev/null differ diff --git a/tests/uploads/fixture/jpg b/tests/uploads/fixture/jpg deleted file mode 100644 index 3cd5038e38..0000000000 Binary files a/tests/uploads/fixture/jpg and /dev/null differ diff --git a/tests/uploads/fixture/png b/tests/uploads/fixture/png deleted file mode 100644 index 5514ad40e9..0000000000 Binary files a/tests/uploads/fixture/png and /dev/null differ diff --git a/tests/uploads/fixture/tif b/tests/uploads/fixture/tif deleted file mode 100644 index 248b50f9cb..0000000000 Binary files a/tests/uploads/fixture/tif and /dev/null differ diff --git a/tests/uploads/fixture/txt b/tests/uploads/fixture/txt deleted file mode 100644 index d3c40d2ea7..0000000000 --- a/tests/uploads/fixture/txt +++ /dev/null @@ -1 +0,0 @@ -mime trigger -- cgit v1.2.1 From 9f3a02d4755409407a26bf75324ac0a8a15d87e2 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 9 Jul 2012 00:10:41 +0100 Subject: [ticket/10941] Removed manual includes of mock classes Also marked a test as incomplete even though this appears to be ignored when actually running the tests. PHPBB3-10941 --- tests/functional/fileupload_test_form.php | 5 +++-- tests/upload/filespec_test.php | 2 -- tests/upload/fileupload_test.php | 1 - 3 files changed, 3 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/functional/fileupload_test_form.php b/tests/functional/fileupload_test_form.php index 48fa75ca4b..87979e6a68 100644 --- a/tests/functional/fileupload_test_form.php +++ b/tests/functional/fileupload_test_form.php @@ -43,11 +43,12 @@ class phpbb_functional_fileupload_test_form extends phpbb_functional_test_case { // Cannot be tested by an admin account which this functional framework // provides - /*$crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $this->markTestIncomplete(); + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); $form = $crawler->selectButton('add_file')->form(); $form['fileupload']->upload($path . 'too-large.png'); $crawler = $this->client->submit($form); - $this->assertEquals(1, $crawler->filter('div#message')->count());*/ + $this->assertEquals(1, $crawler->filter('div#message')->count()); } public function test_valid_file() diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index 7961e8ed64..fc6409999f 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -10,8 +10,6 @@ require_once __DIR__ . '/../../phpBB/includes/functions.php'; require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php'; require_once __DIR__ . '/../../phpBB/includes/functions_upload.php'; -require_once __DIR__ . '/../mock/fileupload.php'; -require_once __DIR__ . '/../mock/request.php'; class phpbb_filespec_test extends phpbb_test_case { diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index 2b3c17b8e0..076855ab56 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -10,7 +10,6 @@ require_once __DIR__ . '/../../phpBB/includes/functions.php'; require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php'; require_once __DIR__ . '/../../phpBB/includes/functions_upload.php'; -require_once __DIR__ . '/../mock/filespec.php'; class phpbb_fileupload_test extends phpbb_test_case { -- cgit v1.2.1 From 6a1c686025067bc570921bf2618415a2f284b647 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 9 Jul 2012 00:36:03 +0100 Subject: [ticket/10941] Moved comment into markTestIncomplete parameter PHPBB3-10941 --- tests/functional/fileupload_test_form.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/functional/fileupload_test_form.php b/tests/functional/fileupload_test_form.php index 87979e6a68..2413cd01d2 100644 --- a/tests/functional/fileupload_test_form.php +++ b/tests/functional/fileupload_test_form.php @@ -41,9 +41,7 @@ class phpbb_functional_fileupload_test_form extends phpbb_functional_test_case public function test_too_large() { - // Cannot be tested by an admin account which this functional framework - // provides - $this->markTestIncomplete(); + $this->markTestIncomplete('Functional tests use an admin account which ignores maximum upload size.'); $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); $form = $crawler->selectButton('add_file')->form(); $form['fileupload']->upload($path . 'too-large.png'); -- cgit v1.2.1 From e0b63df6a4bb7d039e414ac3548ac9fb2e3a8358 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 9 Jul 2012 01:18:04 +0100 Subject: [ticket/10941] Renamed classes and filenames so that tests run Also fixed some minor issues that weren't flagged before because the tests were being ignored. PHPBB3-10941 --- tests/functional/fileupload_form_test.php | 62 +++++++++++++++++++++++++ tests/functional/fileupload_remote_test.php | 72 +++++++++++++++++++++++++++++ tests/functional/fileupload_test_form.php | 61 ------------------------ tests/functional/fileupload_test_remote.php | 71 ---------------------------- 4 files changed, 134 insertions(+), 132 deletions(-) create mode 100644 tests/functional/fileupload_form_test.php create mode 100644 tests/functional/fileupload_remote_test.php delete mode 100644 tests/functional/fileupload_test_form.php delete mode 100644 tests/functional/fileupload_test_remote.php (limited to 'tests') diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php new file mode 100644 index 0000000000..3e1ba71a71 --- /dev/null +++ b/tests/functional/fileupload_form_test.php @@ -0,0 +1,62 @@ +path = __DIR__ . '/fixtures/files/'; + $this->add_lang('posting'); + $this->login(); + } + + public function test_empty_file() + { + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($this->path . 'empty.png'); + $crawler = $this->client->submit($form); + $this->assertEquals('The image file you tried to attach is invalid.', $crawler->filter('div#message p')->text()); + } + + public function test_invalid_extension() + { + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($this->path . 'illegal-extension.bif'); + $crawler = $this->client->submit($form); + $this->assertEquals('The extension bif is not allowed.', $crawler->filter('p.error')->text()); + } + + public function test_too_large() + { + $this->markTestIncomplete('Functional tests use an admin account which ignores maximum upload size.'); + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($path . 'too-large.png'); + $crawler = $this->client->submit($form); + $this->assertEquals(1, $crawler->filter('div#message')->count()); + } + + public function test_valid_file() + { + $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); + $form = $crawler->selectButton('add_file')->form(); + $form['fileupload']->upload($this->path . 'valid.jpg'); + $crawler = $this->client->submit($form); + $this->assertEquals(0, $crawler->filter('p.error')->count()); + $this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->eq(1)->text()); + } +} diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php new file mode 100644 index 0000000000..0deb79acf6 --- /dev/null +++ b/tests/functional/fileupload_remote_test.php @@ -0,0 +1,72 @@ +lang = new phpbb_mock_lang(); + } + + public function tearDown() + { + global $config, $user; + $user = null; + $config = array(); + } + + public function test_invalid_extension() + { + $upload = new fileupload('', array('jpg'), 100); + $file = $upload->remote_upload('http://example.com/image.gif'); + $this->assertEquals('URL_INVALID', $file->error[0]); + } + + public function test_non_existant() + { + $upload = new fileupload('', array('jpg'), 100); + $file = $upload->remote_upload('http://example.com/image.jpg'); + $this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]); + } + + public function test_successful_upload() + { + $upload = new fileupload('', array('gif'), 1000); + $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $this->assertEquals(0, sizeof($file->error)); + $this->assertTrue(file_exists($file->filename)); + } + + public function test_too_large() + { + $upload = new fileupload('', array('gif'), 100); + $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $this->assertEquals('WRONG_FILESIZE', $file->error[0]); + } +} diff --git a/tests/functional/fileupload_test_form.php b/tests/functional/fileupload_test_form.php deleted file mode 100644 index 2413cd01d2..0000000000 --- a/tests/functional/fileupload_test_form.php +++ /dev/null @@ -1,61 +0,0 @@ -path = __DIR__ . '/fixtures/files/'; - $this->add_lang('posting'); - $this->login(); - } - - public function test_empty_file() - { - $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); - $form = $crawler->selectButton('add_file')->form(); - $form['fileupload']->upload($this->path . 'empty.png'); - $crawler = $this->client->submit($form); - $this->assertEquals('The image file you tried to attach is invalid.', $crawler->filter('div#message p')->text()); - } - - public function test_invalid_extension() - { - $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); - $form = $crawler->selectButton('add_file')->form(); - $form['fileupload']->upload($this->path . 'illegal-extension.bif'); - $crawler = $this->client->submit($form); - $this->assertEquals('The extension bif is not allowed.', $crawler->filter('p.error')->text()); - } - - public function test_too_large() - { - $this->markTestIncomplete('Functional tests use an admin account which ignores maximum upload size.'); - $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); - $form = $crawler->selectButton('add_file')->form(); - $form['fileupload']->upload($path . 'too-large.png'); - $crawler = $this->client->submit($form); - $this->assertEquals(1, $crawler->filter('div#message')->count()); - } - - public function test_valid_file() - { - $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); - $form = $crawler->selectButton('add_file')->form(); - $form['fileupload']->upload($this->path . 'valid.jpg'); - $crawler = $this->client->submit($form); - $this->assertEquals(0, $crawler->filter('p.error')->count()); - $this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->eq(1)->text()); - } -} diff --git a/tests/functional/fileupload_test_remote.php b/tests/functional/fileupload_test_remote.php deleted file mode 100644 index ac55a078d4..0000000000 --- a/tests/functional/fileupload_test_remote.php +++ /dev/null @@ -1,71 +0,0 @@ -lang = new phpbb_mock_lang(); - } - - protected function tearDown() - { - global $config, $user; - $user = null; - $config = array(); - } - - public function test_invalid_extension() - { - $upload = new fileupload('', array('jpg'), 100); - $file = $upload->remote_upload('http://example.com/image.gif'); - $this->assertEquals('URL_INVALID', $file->error[0]); - } - - public function test_non_existant() - { - $upload = new fileupload('', array('jpg'), 100); - $file = $upload->remote_upload('http://example.com/image.jpg'); - $this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]); - } - - public function test_successful_upload() - { - $upload = new fileupload('', array('gif'), 1000); - $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); - $this->assertEquals(0, sizeof($file->error)); - $this->assertTrue(file_exists($file->filename)); - } - - public function test_too_large() - { - $upload = new fileupload('', array('gif'), 100); - $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); - $this->assertEquals('WRONG_FILESIZE', $file->error[0]); - } -} -- cgit v1.2.1 From 8d43a6e851bb6caceed6ab3b8a66ffb106c7317d Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 9 Jul 2012 01:24:29 +0100 Subject: [ticket/10941] Replaced use of English with language system PHPBB3-10941 --- tests/functional/fileupload_form_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index 3e1ba71a71..abccd6f987 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -28,7 +28,7 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case $form = $crawler->selectButton('add_file')->form(); $form['fileupload']->upload($this->path . 'empty.png'); $crawler = $this->client->submit($form); - $this->assertEquals('The image file you tried to attach is invalid.', $crawler->filter('div#message p')->text()); + $this->assertEquals($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $crawler->filter('div#message p')->text()); } public function test_invalid_extension() @@ -37,7 +37,7 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case $form = $crawler->selectButton('add_file')->form(); $form['fileupload']->upload($this->path . 'illegal-extension.bif'); $crawler = $this->client->submit($form); - $this->assertEquals('The extension bif is not allowed.', $crawler->filter('p.error')->text()); + $this->assertEquals($this->lang('DISALLOWED_EXTENSION', 'bif'), $crawler->filter('p.error')->text()); } public function test_too_large() -- cgit v1.2.1 From c8059cf7e70ab19f0fad21a7d42d1720392883a7 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 9 Jul 2012 01:29:56 +0100 Subject: [ticket/10941] Fixed form test test_too_large PHPBB3-10941 --- tests/functional/fileupload_form_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index abccd6f987..6ba55eeba7 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -45,9 +45,9 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case $this->markTestIncomplete('Functional tests use an admin account which ignores maximum upload size.'); $crawler = $this->request('GET', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid); $form = $crawler->selectButton('add_file')->form(); - $form['fileupload']->upload($path . 'too-large.png'); + $form['fileupload']->upload($this->path . 'too-large.png'); $crawler = $this->client->submit($form); - $this->assertEquals(1, $crawler->filter('div#message')->count()); + $this->assertEquals($this->lang('WRONG_FILESIZE', '256', 'KiB'), $crawler->filter('p.error')->text()); } public function test_valid_file() -- cgit v1.2.1 From ae9b642b815dce164d0675eee89627f63da97eaf Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 9 Jul 2012 01:48:34 +0100 Subject: [ticket/10941] Added tests/upload/fixture/copies to tracking PHPBB3-10941 --- tests/upload/fixture/copies/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/upload/fixture/copies/.gitkeep (limited to 'tests') diff --git a/tests/upload/fixture/copies/.gitkeep b/tests/upload/fixture/copies/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 -- cgit v1.2.1 From f470eee8abb18fffa834797300f458c1b6478937 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 9 Jul 2012 01:55:11 +0100 Subject: [ticket/10941] Modified tearDown to use DirectoryIterator instead of glob PHPBB3-10941 --- tests/upload/filespec_test.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index fc6409999f..5d75b5fabd 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -83,9 +83,14 @@ class phpbb_filespec_test extends phpbb_test_case $this->config = array(); $user = null; - foreach (glob($this->path . 'copies/*') as $file) + $iterator = new DirectoryIterator($this->path . 'copies'); + foreach ($iterator as $fileinfo) { - unlink($file); + $name = $fileinfo->getFilename(); + if ($name[0] !== '.') + { + unlink($fileinfo->getPathname()); + } } } -- cgit v1.2.1 From 1b3589aae81d44985b5731bf83cce41da6f713e1 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 9 Jul 2012 02:02:10 +0100 Subject: [ticket/10941] Added a comment to ensure tags stay uppercase PHPBB3-10941 --- tests/upload/fixture/txt | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/upload/fixture/txt b/tests/upload/fixture/txt index d3c40d2ea7..a78c858f5c 100644 --- a/tests/upload/fixture/txt +++ b/tests/upload/fixture/txt @@ -1 +1,2 @@ mime trigger +The HTML tags should remain uppercase so that case-insensitivity can be checked. -- cgit v1.2.1 From d046b25124e42f1fb99e1eb04b45420a3af3c4d2 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 9 Jul 2012 02:50:31 +0100 Subject: [ticket/10941] File 'txt' now too big so changed tests to reflect that PHPBB3-10941 --- tests/upload/filespec_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index 5d75b5fabd..34d561eaa0 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -104,7 +104,7 @@ class phpbb_filespec_test extends phpbb_test_case array('jpg', false), array('png', true), array('tif', false), - array('txt', true), + array('txt', false), ); } -- cgit v1.2.1 From 65d7aae2f306d1fed2f26c97caf8b15d178828ce Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 9 Jul 2012 02:51:30 +0100 Subject: [ticket/10941] Removed superfluous array PHPBB3-10941 --- tests/upload/filespec_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index 34d561eaa0..c7ff2e78e0 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -114,7 +114,7 @@ class phpbb_filespec_test extends phpbb_test_case public function test_additional_checks($filename, $expected) { $upload = new phpbb_mock_fileupload(); - $filespec = $this->get_filespec(array('tmp_name', $this->path . $filename)); + $filespec = $this->get_filespec(); $filespec->upload = $upload; $filespec->file_moved = true; $filespec->filesize = $filespec->get_filesize($this->path . $filename); -- cgit v1.2.1 From 1b826842aadc16ad35485479f4bb3bdef03b534c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 16 Jul 2012 16:59:40 +0200 Subject: [ticket/10942] Avoid possible conflicts with magic words in unit tests PHPBB3-10942 --- tests/dbal/case_test.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/dbal/case_test.php b/tests/dbal/case_test.php index 5219defa06..57a1729a39 100644 --- a/tests/dbal/case_test.php +++ b/tests/dbal/case_test.php @@ -18,52 +18,52 @@ class phpbb_dbal_case_test extends phpbb_database_test_case { $db = $this->new_dbal(); - $sql = 'SELECT ' . $db->sql_case('1 = 1', '1', '2') . ' AS num + $sql = 'SELECT ' . $db->sql_case('1 = 1', '1', '2') . ' AS test_num FROM phpbb_config'; $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(1, (int) $db->sql_fetchfield('num')); + $this->assertEquals(1, (int) $db->sql_fetchfield('test_num')); - $sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '2') . ' AS num + $sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '2') . ' AS test_num FROM phpbb_config'; $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(2, (int) $db->sql_fetchfield('num')); + $this->assertEquals(2, (int) $db->sql_fetchfield('test_num')); } public function test_case_string() { $db = $this->new_dbal(); - $sql = 'SELECT ' . $db->sql_case('1 = 1', "'foo'", "'bar'") . ' AS string + $sql = 'SELECT ' . $db->sql_case('1 = 1', "'foo'", "'bar'") . ' AS test_string FROM phpbb_config'; $result = $db->sql_query_limit($sql, 1); - $this->assertEquals('foo', $db->sql_fetchfield('string')); + $this->assertEquals('foo', $db->sql_fetchfield('test_string')); - $sql = 'SELECT ' . $db->sql_case('1 = 0', "'foo'", "'bar'") . ' AS string + $sql = 'SELECT ' . $db->sql_case('1 = 0', "'foo'", "'bar'") . ' AS test_string FROM phpbb_config'; $result = $db->sql_query_limit($sql, 1); - $this->assertEquals('bar', $db->sql_fetchfield('string')); + $this->assertEquals('bar', $db->sql_fetchfield('test_string')); } public function test_case_column() { $db = $this->new_dbal(); - $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS string + $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string FROM phpbb_config WHERE config_name = 'config1'"; $result = $db->sql_query_limit($sql, 1); - $this->assertEquals('config1', $db->sql_fetchfield('string')); + $this->assertEquals('config1', $db->sql_fetchfield('test_string')); - $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS string + $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string FROM phpbb_config WHERE config_value = 'bar'"; $result = $db->sql_query_limit($sql, 1); - $this->assertEquals('bar', $db->sql_fetchfield('string')); + $this->assertEquals('bar', $db->sql_fetchfield('test_string')); } } -- cgit v1.2.1