diff options
Diffstat (limited to 'tests')
77 files changed, 2972 insertions, 289 deletions
diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt index 75a6fc94f6..cede81d59d 100644 --- a/tests/RUNNING_TESTS.txt +++ b/tests/RUNNING_TESTS.txt @@ -17,7 +17,27 @@ PHP extensions Unit tests use several PHP extensions that board code does not use. Currently the following PHP extensions must be installed and enabled to run unit tests: -- ctype +- ctype (also a PHPUnit dependency) +- dom (PHPUnit dependency) +- json (also a phpBB dependency) + +Some of the functionality in phpBB and/or the test suite uses additional +PHP extensions. If these extensions are not loaded, respective tests +will be skipped: + +- apc (APC cache driver) +- bz2 (compress tests) +- interbase, pdo_firebird (Firebird database driver) +- mysql, pdo_mysql (MySQL database driver) +- mysqli, pdo_mysql (MySQLi database driver) +- pcntl (flock class) +- pdo (any database tests) +- pgsql, pdo_pgsql (PostgreSQL database driver) +- redis (https://github.com/nicolasff/phpredis, Redis cache driver) +- simplexml (any database tests) +- sqlite, pdo_sqlite (SQLite database driver, requires SQLite 2.x support + in pdo_sqlite) +- zlib (compress tests) Database Tests -------------- @@ -30,7 +50,7 @@ example for mysqli can be found below. More information on configuration options can be found on the wiki (see below). <?php - $dbms = 'mysqli'; + $dbms = 'phpbb_db_driver_mysqli'; $dbhost = 'localhost'; $dbport = ''; $dbname = 'database'; @@ -44,7 +64,7 @@ to use in the environment as follows: $ PHPBB_TEST_CONFIG=tests/test_config.php phpunit Alternatively you can specify parameters in the environment, so e.g. the -following will run phpunit with the same parameters as in the shown +following will run PHPUnit with the same parameters as in the shown test_config.php file: $ PHPBB_TEST_DBMS='mysqli' PHPBB_TEST_DBHOST='localhost' \ diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index 8c7fbc7128..d0dcce5bbf 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -2,28 +2,264 @@ /** * * @package testing -* @version $Id$ -* @copyright (c) 2008 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/bbcode/bbcode_parser_base.php'; -// require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode/bbcode_parser.php'; +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'; class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase { - public function test_both_passes() + public function bbcode_firstpass_data() { - $this->markTestIncomplete('New bbcode parser has not been backported from feature/ascraeus-experiment yet.'); - - $parser = new phpbb_bbcode_parser(); + return array( + // Default bbcodes from in their simplest way + array( + 'Test default bbcodes: simple bold', + '[b]bold[/b]', + '[b:]bold[/b:]', + ), + array( + 'Test default bbcodes: simple underlined', + '[u]underlined[/u]', + '[u:]underlined[/u:]', + ), + array( + 'Test default bbcodes: simple italic', + '[i]italic[/i]', + '[i:]italic[/i:]', + ), + array( + 'Test default bbcodes: simple color rgb', + '[color=#FF0000]colored[/color]', + '[color=#FF0000:]colored[/color:]', + ), + array( + 'Test default bbcodes: simple color name', + '[color=red]colored[/color]', + '[color=red:]colored[/color:]', + ), + array( + 'Test default bbcodes: simple size', + '[size=75]smaller[/size]', + '[size=75:]smaller[/size:]', + ), + array( + 'Test default bbcodes: simple quote', + '[quote]quoted[/quote]', + '[quote:]quoted[/quote:]', + ), + array( + 'Test default bbcodes: simple quote with username', + '[quote="username"]quoted[/quote]', + '[quote="username":]quoted[/quote:]', + ), + array( + 'Test default bbcodes: simple code', + '[code]unparsed code[/code]', + '[code:]unparsed code[/code:]', + ), + array( + 'Test default bbcodes: simple php code', + '[code=php]unparsed code[/code]', + '[code=php:]<span class="syntaxdefault">unparsed code</span>[/code:]', + ), + array( + 'Test default bbcodes: simple list', + '[list]no item[/list]', + '[list:]no item[/list:u:]', + ), + array( + 'Test default bbcodes: simple list-item only', + '[*]unparsed', + '[*]unparsed', + ), + array( + 'Test default bbcodes: simple list-item', + '[list][*]item[/list]', + '[list:][*:]item[/*:m:][/list:u:]', + ), + array( + 'Test default bbcodes: simple list-item closed', + '[list][*]item[/*][/list]', + '[list:][*:]item[/*:][/list:u:]', + ), + array( + 'Test default bbcodes: simple list-item numbered', + '[list=1][*]item[/list]', + '[list=1:][*:]item[/*:m:][/list:o:]', + ), + array( + 'Test default bbcodes: simple list-item alpha', + '[list=a][*]item[/list]', + '[list=a:][*:]item[/*:m:][/list:o:]', + ), + array( + 'Test default bbcodes: simple list-item roman', + '[list=i][*]item[/list]', + '[list=i:][*:]item[/*:m:][/list:o:]', + ), + array( + 'Test default bbcodes: simple list-item disc', + '[list=disc][*]item[/list]', + '[list=disc:][*:]item[/*:m:][/list:u:]', + ), + array( + 'Test default bbcodes: simple list-item circle', + '[list=circle][*]item[/list]', + '[list=circle:][*:]item[/*:m:][/list:u:]', + ), + array( + 'Test default bbcodes: simple list-item square', + '[list=square][*]item[/list]', + '[list=square:][*:]item[/*:m:][/list:u:]', + ), + array( + 'Test default bbcodes: simple img', + '[img]https://area51.phpbb.com/images/area51.png[/img]', + '[img:]https://area51.phpbb.com/images/area51.png[/img:]', + ), + array( + 'Test default bbcodes: simple url', + '[url]https://area51.phpbb.com/[/url]', + '[url:]https://area51.phpbb.com/[/url:]', + ), + array( + 'Test default bbcodes: simple url with description', + '[url=https://area51.phpbb.com/]Area51[/url]', + '[url=https://area51.phpbb.com/:]Area51[/url:]', + ), + array( + 'Test default bbcodes: simple email', + '[email]bbcode-test@phpbb.com[/email]', + '[email:]bbcode-test@phpbb.com[/email:]', + ), + array( + 'Test default bbcodes: simple email with description', + '[email=bbcode-test@phpbb.com]Email[/email]', + '[email=bbcode-test@phpbb.com:]Email[/email:]', + ), + array( + 'Test default bbcodes: simple attachment', + '[attachment=0]filename[/attachment]', + '[attachment=0:]<!-- ia0 -->filename<!-- ia0 -->[/attachment:]', + ), - $result = $parser->first_pass('[i]Italic [u]underlined text[/u][/i]'); - $result = $parser->second_pass($result); + // Special cases for quote which were reported as bugs before + array( + 'PHPBB3-1401 - correct: parsed', + '[quote="[test]test"]test [ test[/quote]', + '[quote="[test]test":]test [ test[/quote:]', + ), + array( + 'PHPBB3-6117 - correct: parsed', + '[quote]test[/quote] test ] and [ test [quote]test[/quote]', + '[quote:]test[/quote:] test ] and [ test [quote:]test[/quote:]', + ), + array( + 'PHPBB3-6200 - correct: parsed', + '[quote="["]test[/quote]', + '[quote="[":]test[/quote:]', + ), + array( + 'PHPBB3-9364 - quoted: "test[/[/b]quote] test" / non-quoted: "[/quote] test" - also failed if layout distorted', + '[quote]test[/[/b]quote] test [/quote][/quote] test', + '[quote:]test[/[/b]quote] test [/quote:][/quote] test', + ), + array( + 'PHPBB3-8096 - first quote tag parsed, second quote tag unparsed', + '[quote="a"]a[/quote][quote="a]a[/quote]', + '[quote="a":]a[/quote:][quote="a]a[/quote]', + ), - $expected = '<span style="font-style: italic">Italic <span style="text-decoration: underline">underlined text</span></span>'; + // Simple bbcodes nesting + array( + 'Allow textual bbcodes in textual bbcodes', + '[b]bold [i]bold + italic[/i][/b]', + '[b:]bold [i:]bold + italic[/i:][/b:]', + ), + array( + 'Allow textual bbcodes in url with description', + '[url=https://area51.phpbb.com/]Area51 [i]italic[/i][/url]', + '[url=https://area51.phpbb.com/:]Area51 [i:]italic[/i:][/url:]', + ), + array( + 'Allow url with description in textual bbcodes', + '[i]italic [url=https://area51.phpbb.com/]Area51[/url][/i]', + '[i:]italic [url=https://area51.phpbb.com/:]Area51[/url:][/i:]', + ), - $this->assertEquals($expected, $result, 'Simple nested BBCode first+second pass'); + // Nesting bbcodes into quote usernames + array( + 'Allow textual bbcodes in usernames', + '[quote="[i]test[/i]"]test[/quote]', + '[quote="[i:]test[/i:]":]test[/quote:]', + ), + array( + 'Allow links bbcodes in usernames', + '[quote="[url=https://area51.phpbb.com/]test[/url]"]test[/quote]', + '[quote="[url=https://area51.phpbb.com/:]test[/url:]":]test[/quote:]', + ), + array( + 'Allow img bbcodes in usernames - Username displayed the image', + '[quote="[img]https://area51.phpbb.com/images/area51.png[/img]"]test[/quote]', + '[quote="[img:]https://area51.phpbb.com/images/area51.png[/img:]":]test[/quote:]', + ), + array( + 'Disallow flash bbcodes in usernames - Username displayed as [flash]http://www.phpbb.com/[/flash]', + '[quote="[flash]http://www.phpbb.com/[/flash]"]test[/quote]', + '[quote="[flash]http://www.phpbb.com/[/flash]":]test[/quote:]', + ), + array( + 'Disallow quote bbcodes in usernames - Username displayed as [quote]test[/quote]', + '[quote="[quote]test[/quote]"]test[/quote]', + '[quote="[quote]test[/quote]":]test[/quote:]', + ), + + // Do not parse bbcodes in code boxes + array( + 'Do not parse textual bbcodes in code', + '[code]unparsed code [b]bold [i]bold + italic[/i][/b][/code]', + '[code:]unparsed code [b]bold [i]bold + italic[/i][/b][/code:]', + ), + array( + 'Do not parse quote bbcodes in code', + '[code]unparsed code [quote="username"]quoted[/quote][/code]', + '[code:]unparsed code [quote="username"]quoted[/quote][/code:]', + ), + + // New user friendly mixed nesting + array( + 'Textual bbcode nesting into textual bbcode', + '[b]bold [i]bold + italic[/b] italic[/i]', + '[b:]bold [i:]bold + italic[/b:] italic[/i:]', + 'Incomplete test case: secondpass parses as [b:]bold [i:]bold + italic[/i:] italic[/b:]', + ), + ); + } + + /** + * @dataProvider bbcode_firstpass_data + */ + public function test_bbcode_firstpass($description, $message, $expected, $incomplete = false) + { + if ($incomplete) + { + $this->markTestIncomplete($incomplete); + } + + global $user, $request; + $user = new phpbb_mock_user; + $request = new phpbb_mock_request; + + $bbcode = new bbcode_firstpass(); + $bbcode->message = $message; + $bbcode->bbcode_init(false); + $bbcode->parse_bbcode(); + $this->assertEquals($expected, $bbcode->message); } } diff --git a/tests/cache/common_test_case.php b/tests/cache/common_test_case.php index fa298ec9ae..a5bc2bfda9 100644 --- a/tests/cache/common_test_case.php +++ b/tests/cache/common_test_case.php @@ -64,9 +64,10 @@ abstract class phpbb_cache_common_test_case extends phpbb_database_test_case public function test_cache_sql() { - global $db, $cache; + global $db, $cache, $phpbb_root_path, $phpEx; + $config = new phpbb_config(array()); $db = $this->new_dbal(); - $cache = new phpbb_cache_service($this->driver); + $cache = new phpbb_cache_service($this->driver, $config, $db, $phpbb_root_path, $phpEx); $sql = "SELECT * FROM phpbb_config WHERE config_name = 'foo'"; diff --git a/tests/cache/null_driver_test.php b/tests/cache/null_driver_test.php index 86553d4dc5..43a0cc806c 100644 --- a/tests/cache/null_driver_test.php +++ b/tests/cache/null_driver_test.php @@ -47,9 +47,10 @@ class phpbb_cache_null_driver_test extends phpbb_database_test_case public function test_cache_sql() { - global $db, $cache; + global $db, $cache, $phpbb_root_path, $phpEx; + $config = new phpbb_config(array()); $db = $this->new_dbal(); - $cache = new phpbb_cache_service($this->driver); + $cache = new phpbb_cache_service($this->driver, $config, $db, $phpbb_root_path, $phpEx); $sql = "SELECT * FROM phpbb_config WHERE config_name = 'foo'"; diff --git a/tests/compress/compress_test.php b/tests/compress/compress_test.php index ac8dd358d3..6623f7ed8a 100644 --- a/tests/compress/compress_test.php +++ b/tests/compress/compress_test.php @@ -38,10 +38,16 @@ class phpbb_compress_test extends phpbb_test_case $phpbb_root_path = ''; $this->path = dirname(__FILE__) . '/fixtures/'; + } - if (!@extension_loaded('zlib') || !@extension_loaded('bz2')) + protected function check_extensions($extensions) + { + foreach ($extensions as $extension) { - $this->markTestSkipped('PHP needs to be compiled with --with-zlib and --with-bz2 in order to run these tests'); + if (!@extension_loaded($extension)) + { + $this->markTestSkipped("$extension extension is not loaded"); + } } } @@ -114,17 +120,18 @@ class phpbb_compress_test extends phpbb_test_case public function tar_archive_list() { return array( - array('archive.tar', '.tar'), - array('archive.tar.gz', '.tar.gz'), - array('archive.tar.bz2', '.tar.bz2'), + array('archive.tar', '.tar', array()), + array('archive.tar.gz', '.tar.gz', array('zlib')), + array('archive.tar.bz2', '.tar.bz2', array('bz2')), ); } /** * @dataProvider tar_archive_list */ - public function test_extract_tar($filename, $type) + public function test_extract_tar($filename, $type, $extensions) { + $this->check_extensions($extensions); $compress = new compress_tar('r', $this->path . $filename); $compress->extract('tests/compress/' . self::EXTRACT_DIR); $this->valid_extraction(); @@ -141,8 +148,10 @@ class phpbb_compress_test extends phpbb_test_case * @depends test_extract_tar * @dataProvider tar_archive_list */ - public function test_compress_tar($filename, $type) + public function test_compress_tar($filename, $type, $extensions) { + $this->check_extensions($extensions); + $tar = dirname(__FILE__) . self::ARCHIVE_DIR . $filename; $compress = new compress_tar('w', $tar); $this->archive_files($compress); @@ -160,6 +169,8 @@ class phpbb_compress_test extends phpbb_test_case */ public function test_compress_zip() { + $this->check_extensions(array('zlib')); + $zip = dirname(__FILE__) . self::ARCHIVE_DIR . 'archive.zip'; $compress = new compress_zip('w', $zip); $this->archive_files($compress); diff --git a/tests/dbal/connect_test.php b/tests/dbal/connect_test.php new file mode 100644 index 0000000000..1e352d6b03 --- /dev/null +++ b/tests/dbal/connect_test.php @@ -0,0 +1,41 @@ +<?php +/** +* +* @package testing +* @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'; + +class phpbb_dbal_connect_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/../fixtures/empty.xml'); + } + + public function test_failing_connect() + { + global $phpbb_root_path, $phpEx; + + $config = $this->get_database_config(); + + $db = new $config['dbms'](); + + // Failure to connect results in a trigger_error call in dbal. + // phpunit converts triggered errors to exceptions. + // In particular there should be no fatals here. + try + { + $db->sql_connect($config['dbhost'], 'phpbbogus', 'phpbbogus', 'phpbbogus', $config['dbport']); + $this->assertFalse(true); + } + catch (Exception $e) + { + // should have a legitimate message + $this->assertNotEmpty($e->getMessage()); + } + } +} diff --git a/tests/dbal/fixtures/migrator.xml b/tests/dbal/fixtures/migrator.xml new file mode 100644 index 0000000000..25be4d4129 --- /dev/null +++ b/tests/dbal/fixtures/migrator.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_migrations"> + <column>migration_name</column> + <column>migration_depends_on</column> + <column>migration_schema_done</column> + <column>migration_data_done</column> + <column>migration_data_state</column> + <column>migration_start_time</column> + <column>migration_end_time</column> + <row> + <value>installed_migration</value> + <value></value> + <value>1</value> + <value>1</value> + <value></value> + <value>1234</value> + <value>5678</value> + </row> + </table> + <table name="phpbb_config"> + <column>config_name</column> + <column>config_value</column> + <row> + <value>foo</value> + <value>bar</value> + </row> + </table> +</dataset> diff --git a/tests/dbal/fixtures/migrator_module.xml b/tests/dbal/fixtures/migrator_module.xml new file mode 100644 index 0000000000..32afe7e6f3 --- /dev/null +++ b/tests/dbal/fixtures/migrator_module.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_modules"> + <column>module_id</column> + <column>module_enabled</column> + <column>module_display</column> + <column>module_basename</column> + <column>module_class</column> + <column>parent_id</column> + <column>left_id</column> + <column>right_id</column> + <column>module_langname</column> + <column>module_mode</column> + <column>module_auth</column> + <row> + <value>1</value> + <value>1</value> + <value>1</value> + <value></value> + <value>acp</value> + <value>0</value> + <value>1</value> + <value>4</value> + <value>ACP_CAT</value> + <value></value> + <value></value> + </row> + <row> + <value>2</value> + <value>1</value> + <value>1</value> + <value>acp_test</value> + <value>acp</value> + <value>1</value> + <value>2</value> + <value>3</value> + <value>ACP_MODULE</value> + <value>test</value> + <value></value> + </row> + </table> +</dataset> diff --git a/tests/dbal/fixtures/migrator_permission.xml b/tests/dbal/fixtures/migrator_permission.xml new file mode 100644 index 0000000000..08cec42a42 --- /dev/null +++ b/tests/dbal/fixtures/migrator_permission.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_acl_options"> + <column>auth_option_id</column> + <column>auth_option</column> + <column>is_global</column> + <column>is_local</column> + <column>founder_only</column> + <row> + <value>1</value> + <value>global</value> + <value>1</value> + <value>0</value> + <value>0</value> + </row> + <row> + <value>2</value> + <value>local</value> + <value>0</value> + <value>1</value> + <value>0</value> + </row> + <row> + <value>3</value> + <value>both</value> + <value>1</value> + <value>1</value> + <value>0</value> + </row> + </table> +</dataset> diff --git a/tests/dbal/migration/dummy.php b/tests/dbal/migration/dummy.php new file mode 100644 index 0000000000..0ac6e733a1 --- /dev/null +++ b/tests/dbal/migration/dummy.php @@ -0,0 +1,27 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_dbal_migration_dummy extends phpbb_db_migration +{ + static public function depends_on() + { + return array('installed_migration'); + } + + function update_schema() + { + return array( + 'add_columns' => array( + 'phpbb_config' => array( + 'extra_column' => array('UINT', 1), + ), + ), + ); + } +} diff --git a/tests/dbal/migration/fail.php b/tests/dbal/migration/fail.php new file mode 100644 index 0000000000..f88d8169f5 --- /dev/null +++ b/tests/dbal/migration/fail.php @@ -0,0 +1,41 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* +*/ + +class phpbb_dbal_migration_fail extends phpbb_db_migration +{ + function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'config' => array( + 'test_column' => array('BOOL', 1), + ), + ), + ); + } + + function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'config' => array( + 'test_column', + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('foobar3', true)), + array('config.update', array('does_not_exist', true)), + ); + } +} diff --git a/tests/dbal/migration/if.php b/tests/dbal/migration/if.php new file mode 100644 index 0000000000..83fe21bd21 --- /dev/null +++ b/tests/dbal/migration/if.php @@ -0,0 +1,44 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_dbal_migration_if extends phpbb_db_migration +{ + function update_schema() + { + return array(); + } + + function update_data() + { + return array( + array('if', array( + true, + array('custom', array(array(&$this, 'test_true'))), + )), + array('if', array( + false, + array('custom', array(array(&$this, 'test_false'))), + )), + ); + } + + function test_true() + { + global $migrator_test_if_true_failed; + + $migrator_test_if_true_failed = false; + } + + function test_false() + { + global $migrator_test_if_false_failed; + + $migrator_test_if_false_failed = true; + } +} diff --git a/tests/dbal/migration/installed.php b/tests/dbal/migration/installed.php new file mode 100644 index 0000000000..01829f7a99 --- /dev/null +++ b/tests/dbal/migration/installed.php @@ -0,0 +1,30 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_dbal_migration_installed extends phpbb_db_migration +{ + function effectively_installed() + { + return true; + } + + function update_data() + { + return array( + array('custom', array(array(&$this, 'test'))), + ); + } + + function test() + { + global $migrator_test_installed_failed; + + $migrator_test_installed_failed = true; + } +} diff --git a/tests/dbal/migration/recall.php b/tests/dbal/migration/recall.php new file mode 100644 index 0000000000..6c2f04bf08 --- /dev/null +++ b/tests/dbal/migration/recall.php @@ -0,0 +1,38 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_dbal_migration_recall extends phpbb_db_migration +{ + function update_schema() + { + return array(); + } + + function update_data() + { + return array( + array('custom', array(array(&$this, 'test_call'))), + ); + } + + // This function should be called 10 times + function test_call($input) + { + global $migrator_test_call_input; + + $migrator_test_call_input = (int) $input; + + if ($migrator_test_call_input < 10) + { + return ($migrator_test_call_input + 1); + } + + return; + } +} diff --git a/tests/dbal/migration/revert.php b/tests/dbal/migration/revert.php new file mode 100644 index 0000000000..ac01987cd4 --- /dev/null +++ b/tests/dbal/migration/revert.php @@ -0,0 +1,40 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_dbal_migration_revert extends phpbb_db_migration +{ + function update_schema() + { + return array( + 'add_columns' => array( + 'phpbb_config' => array( + 'bar_column' => array('UINT', 1), + ), + ), + ); + } + + function revert_schema() + { + return array( + 'drop_columns' => array( + 'phpbb_config' => array( + 'bar_column', + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('foobartest', 0)), + ); + } +} diff --git a/tests/dbal/migration/revert_with_dependency.php b/tests/dbal/migration/revert_with_dependency.php new file mode 100644 index 0000000000..ca2c070e8c --- /dev/null +++ b/tests/dbal/migration/revert_with_dependency.php @@ -0,0 +1,16 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_dbal_migration_revert_with_dependency extends phpbb_db_migration +{ + static public function depends_on() + { + return array('phpbb_dbal_migration_revert'); + } +} diff --git a/tests/dbal/migration/unfulfillable.php b/tests/dbal/migration/unfulfillable.php new file mode 100644 index 0000000000..6d375e6880 --- /dev/null +++ b/tests/dbal/migration/unfulfillable.php @@ -0,0 +1,26 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +class phpbb_dbal_migration_unfulfillable extends phpbb_db_migration +{ + static public function depends_on() + { + return array('installed_migration', 'phpbb_dbal_migration_dummy', 'non_existant_migration'); + } + + function update_schema() + { + trigger_error('Schema update of migration with unfulfillable dependency was run!'); + } + + function update_data() + { + trigger_error('Data update of migration with unfulfillable dependency was run!'); + } +} diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php new file mode 100644 index 0000000000..9460e76f37 --- /dev/null +++ b/tests/dbal/migrator_test.php @@ -0,0 +1,257 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/db/migrator.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/migration.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; + +require_once dirname(__FILE__) . '/migration/dummy.php'; +require_once dirname(__FILE__) . '/migration/unfulfillable.php'; +require_once dirname(__FILE__) . '/migration/if.php'; +require_once dirname(__FILE__) . '/migration/recall.php'; +require_once dirname(__FILE__) . '/migration/revert.php'; +require_once dirname(__FILE__) . '/migration/revert_with_dependency.php'; +require_once dirname(__FILE__) . '/migration/fail.php'; +require_once dirname(__FILE__) . '/migration/installed.php'; + +class phpbb_dbal_migrator_test extends phpbb_database_test_case +{ + protected $db; + protected $db_tools; + protected $migrator; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator.xml'); + } + + public function setUp() + { + parent::setUp(); + + $this->db = $this->new_dbal(); + $this->db_tools = new phpbb_db_tools($this->db); + + $this->config = new phpbb_config_db($this->db, new phpbb_mock_cache, 'phpbb_config'); + + $tools = array( + new phpbb_db_migration_tool_config($this->config), + ); + $this->migrator = new phpbb_db_migrator($this->config, $this->db, $this->db_tools, 'phpbb_migrations', dirname(__FILE__) . '/../../phpBB/', 'php', 'phpbb_', $tools); + } + + public function test_update() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_dummy')); + + // schema + $this->migrator->update(); + $this->assertFalse($this->migrator->finished()); + + $this->assertSqlResultEquals( + array(array('success' => '1')), + "SELECT 1 as success + FROM phpbb_migrations + WHERE migration_name = 'phpbb_dbal_migration_dummy' + AND migration_start_time >= " . (time() - 1) . " + AND migration_start_time <= " . (time() + 1), + 'Start time set correctly' + ); + + // data + $this->migrator->update(); + $this->assertTrue($this->migrator->finished()); + + $this->assertSqlResultEquals( + array(array('extra_column' => '1')), + "SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'", + 'Dummy migration created extra_column with value 1 in all rows.' + ); + + $this->assertSqlResultEquals( + array(array('success' => '1')), + "SELECT 1 as success + FROM phpbb_migrations + WHERE migration_name = 'phpbb_dbal_migration_dummy' + AND migration_start_time <= migration_end_time + AND migration_end_time >= " . (time() - 1) . " + AND migration_end_time <= " . (time() + 1), + 'End time set correctly' + ); + + // cleanup + $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); + } + + public function test_unfulfillable() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_unfulfillable', 'phpbb_dbal_migration_dummy')); + + while (!$this->migrator->finished()) + { + $this->migrator->update(); + } + + $this->assertTrue($this->migrator->finished()); + + $this->assertSqlResultEquals( + array(array('extra_column' => '1')), + "SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'", + 'Dummy migration was run, even though an unfulfillable migration was found.' + ); + + $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); + } + + public function test_if() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_if')); + + // Don't like this, but I'm not sure there is any other way to do this + global $migrator_test_if_true_failed, $migrator_test_if_false_failed; + $migrator_test_if_true_failed = true; + $migrator_test_if_false_failed = false; + + while (!$this->migrator->finished()) + { + $this->migrator->update(); + } + + if ($migrator_test_if_true_failed) + { + $this->fail('True test failed'); + } + + if ($migrator_test_if_false_failed) + { + $this->fail('False test failed'); + } + } + + public function test_recall() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_recall')); + + global $migrator_test_call_input; + + // Run the schema first + $this->migrator->update(); + + $i = 0; + while (!$this->migrator->finished()) + { + $this->migrator->update(); + + $this->assertSame($i, $migrator_test_call_input); + + $i++; + } + + $this->assertSame(10, $migrator_test_call_input); + } + + public function test_revert() + { + // Make sure there are no other migrations in the db, this could cause issues + $this->db->sql_query("DELETE FROM phpbb_migrations"); + $this->migrator->load_migration_state(); + + $this->migrator->set_migrations(array('phpbb_dbal_migration_revert', 'phpbb_dbal_migration_revert_with_dependency')); + + $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert')); + $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency')); + + // Install the migration first + while (!$this->migrator->finished()) + { + $this->migrator->update(); + } + + $this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_revert') !== false); + $this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency') !== false); + + $this->assertSqlResultEquals( + array(array('bar_column' => '1')), + "SELECT bar_column FROM phpbb_config WHERE config_name = 'foo'", + 'Installing revert migration failed to create bar_column.' + ); + + $this->assertTrue(isset($this->config['foobartest'])); + + while ($this->migrator->migration_state('phpbb_dbal_migration_revert') !== false) + { + $this->migrator->revert('phpbb_dbal_migration_revert'); + } + + $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert')); + $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency')); + + $this->assertFalse(isset($this->config['foobartest'])); + + $sql = 'SELECT * FROM phpbb_config'; + $result = $this->db->sql_query_limit($sql, 1); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (isset($row['bar_column'])) + { + $this->fail('Revert did not remove test_column.'); + } + } + + public function test_fail() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_fail')); + + $this->assertFalse(isset($this->config['foobar3'])); + + try + { + while (!$this->migrator->finished()) + { + $this->migrator->update(); + } + } + catch (phpbb_db_migration_exception $e) {} + + // Failure should have caused an automatic roll-back, so this should not exist. + $this->assertFalse(isset($this->config['foobar3'])); + + $sql = 'SELECT * FROM phpbb_config'; + $result = $this->db->sql_query_limit($sql, 1); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (isset($row['test_column'])) + { + $this->fail('Revert did not remove test_column.'); + } + } + + public function test_installed() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_installed')); + + global $migrator_test_installed_failed; + $migrator_test_installed_failed = false; + + while (!$this->migrator->finished()) + { + $this->migrator->update(); + } + + $this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_installed') !== false); + + if ($migrator_test_installed_failed) + { + $this->fail('Installed test failed'); + } + } +} diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php new file mode 100644 index 0000000000..7d582f230b --- /dev/null +++ b/tests/dbal/migrator_tool_config_test.php @@ -0,0 +1,124 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/config.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php'; + +class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case +{ + public function setup() + { + $this->config = new phpbb_config(array()); + + $this->tool = new phpbb_db_migration_tool_config($this->config); + + parent::setup(); + } + + public function test_add() + { + try + { + $this->tool->add('foo', 'bar'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals('bar', $this->config['foo']); + + try + { + $this->tool->add('foo', 'bar'); + $this->fail('Exception not thrown'); + } + catch (Exception $e) {} + } + + public function test_update() + { + $this->config->set('foo', 'bar'); + try + { + $this->tool->update('foo', 'bar2'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals('bar2', $this->config['foo']); + } + + public function test_update_if_equals() + { + $this->config->set('foo', 'bar'); + + try + { + $this->tool->update_if_equals('', 'foo', 'bar2'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals('bar', $this->config['foo']); + + try + { + $this->tool->update_if_equals('bar', 'foo', 'bar2'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals('bar2', $this->config['foo']); + } + + public function test_remove() + { + $this->config->set('foo', 'bar'); + + try + { + $this->tool->remove('foo'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertFalse(isset($this->config['foo'])); + } + + public function test_reverse() + { + $this->config->set('foo', 'bar'); + + try + { + $this->tool->reverse('add', 'foo'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertFalse(isset($this->config['foo'])); + + $this->config->set('foo', 'bar'); + + try + { + $this->tool->reverse('update_if_equals', 'test', 'foo', 'bar'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals('test', $this->config['foo']); + } +} diff --git a/tests/dbal/migrator_tool_module.php b/tests/dbal/migrator_tool_module.php new file mode 100644 index 0000000000..6937b6f8c5 --- /dev/null +++ b/tests/dbal/migrator_tool_module.php @@ -0,0 +1,150 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/module.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php'; + +class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_module.xml'); + } + + public function setup() + { + // Need global $db, $user for delete_module function in acp_modules + global $phpbb_root_path, $phpEx, $skip_add_log, $db, $user; + + parent::setup(); + + // Force add_log function to not be used + $skip_add_log = true; + + $db = $this->db = $this->new_dbal(); + $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx); + $user = $this->user = new phpbb_user(); + + $this->tool = new phpbb_db_migration_tool_module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules'); + } + + public function exists_data() + { + return array( + // Test the category + array( + '', + 'ACP_CAT', + true, + ), + array( + 0, + 'ACP_CAT', + true, + ), + + // Test the module + array( + '', + 'ACP_MODULE', + false, + ), + array( + false, + 'ACP_MODULE', + true, + ), + array( + 'ACP_CAT', + 'ACP_MODULE', + true, + ), + ); + } + + /** + * @dataProvider exists_data + */ + public function test_exists($parent, $module, $expected) + { + $this->assertEquals($expected, $this->tool->exists('acp', $parent, $module)); + } + + public function test_add() + { + try + { + $this->tool->add('acp', 0, 'ACP_NEW_CAT'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('acp', 0, 'ACP_NEW_CAT')); + + // Should throw an exception when trying to add a module that already exists + try + { + $this->tool->add('acp', 0, 'ACP_NEW_CAT'); + $this->fail('Exception not thrown'); + } + catch (Exception $e) {} + + try + { + $this->tool->add('acp', 'ACP_NEW_CAT', array( + 'module_basename' => 'acp_new_module', + 'module_langname' => 'ACP_NEW_MODULE', + 'module_mode' => 'test', + 'module_auth' => '', + )); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('acp', 'ACP_NEW_CAT', 'ACP_NEW_MODULE')); + } + + public function test_remove() + { + try + { + $this->tool->remove('acp', 'ACP_CAT', 'ACP_MODULE'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(false, $this->tool->exists('acp', 'ACP_CAT', 'ACP_MODULE')); + } + + public function test_reverse() + { + try + { + $this->tool->add('acp', 0, 'ACP_NEW_CAT'); + } + catch (Exception $e) + { + $this->fail($e); + } + + try + { + $this->tool->reverse('add', 'acp', 0, 'ACP_NEW_CAT'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertFalse($this->tool->exists('acp', 0, 'ACP_NEW_CAT')); + } +} diff --git a/tests/dbal/migrator_tool_permission.php b/tests/dbal/migrator_tool_permission.php new file mode 100644 index 0000000000..438ab2b28e --- /dev/null +++ b/tests/dbal/migrator_tool_permission.php @@ -0,0 +1,159 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/permission.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php'; + +class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_permission.xml'); + } + + public function setup() + { + // Global $db and $cache are needed in acp/auth.php constructor + global $phpbb_root_path, $phpEx, $db, $cache; + + parent::setup(); + + $db = $this->db = $this->new_dbal(); + $cache = $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx); + $this->auth = new phpbb_auth(); + + $this->tool = new phpbb_db_migration_tool_permission($this->db, $this->cache, $this->auth, $phpbb_root_path, $phpEx); + } + + public function exists_data() + { + return array( + array( + 'global', + true, + true, + ), + array( + 'local', + false, + true, + ), + array( + 'both', + true, + true, + ), + array( + 'both', + false, + true, + ), + array( + 'does_not_exist', + true, + false, + ), + ); + } + + /** + * @dataProvider exists_data + */ + public function test_exists($auth_option, $global, $expected) + { + $this->assertEquals($expected, $this->tool->exists($auth_option, $global)); + } + + public function test_add() + { + try + { + $this->tool->add('new', true); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('new', true)); + $this->assertEquals(false, $this->tool->exists('new', false)); + + try + { + $this->tool->add('new', false); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('new', false)); + + // Should fail (duplicate) + try + { + $this->tool->add('new', true); + $this->fail('Did not throw exception on duplicate'); + } + catch (Exception $e) {} + } + + public function test_remove() + { + try + { + $this->tool->remove('global', true); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(false, $this->tool->exists('global', true)); + + try + { + $this->tool->remove('both', false); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(false, $this->tool->exists('both', false)); + + // Should fail (does not exist) + try + { + $this->tool->remove('new', true); + $this->fail('Did not throw exception on duplicate'); + } + catch (Exception $e) {} + } + + public function test_reverse() + { + try + { + $this->tool->reverse('remove', 'global_test', true); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertTrue($this->tool->exists('global_test', true)); + + try + { + $this->tool->reverse('add', 'global_test', true); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertFalse($this->tool->exists('global_test', true)); + } +} diff --git a/tests/dbal/write_sequence_test.php b/tests/dbal/write_sequence_test.php index 8975cfbfb1..f382a971a5 100644 --- a/tests/dbal/write_sequence_test.php +++ b/tests/dbal/write_sequence_test.php @@ -33,6 +33,10 @@ class phpbb_dbal_write_sequence_test extends phpbb_database_test_case { $db = $this->new_dbal(); + // dbal uses cache + global $cache; + $cache = new phpbb_mock_cache(); + $sql = 'INSERT INTO phpbb_users ' . $db->sql_build_array('INSERT', array( 'username' => $username, 'username_clean' => $username, diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php index c2b8a0fc0b..6de8803df9 100644 --- a/tests/di/create_container_test.php +++ b/tests/di/create_container_test.php @@ -9,7 +9,6 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_container.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/dbal.php'; class phpbb_di_container_test extends phpbb_test_case { @@ -52,7 +51,7 @@ class phpbb_di_container_test extends phpbb_test_case } } -class dbal_container_mock extends dbal +class phpbb_db_driver_container_mock extends phpbb_db_driver { public function sql_connect() { diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 5cde5bccdb..9032afbd73 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -25,14 +25,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case { parent::setUp(); - $this->extension_manager = new phpbb_extension_manager( - $this->new_dbal(), - new phpbb_config(array()), - 'phpbb_ext', - dirname(__FILE__) . '/', - '.php', - new phpbb_mock_cache - ); + $this->extension_manager = $this->create_extension_manager(); } public function test_available() @@ -89,15 +82,30 @@ class phpbb_extension_manager_test extends phpbb_database_test_case public function test_enabled_no_cache() { - $extension_manager = new phpbb_extension_manager( - $this->new_dbal(), - new phpbb_config(array()), - 'phpbb_ext', - dirname(__FILE__) . '/', - '.php' - ); + $extension_manager = $this->create_extension_manager(false); $this->assertEquals(array('foo'), array_keys($extension_manager->all_enabled())); } + protected function create_extension_manager($with_cache = true) + { + + $config = new phpbb_config(array()); + $db = $this->new_dbal(); + $db_tools = new phpbb_db_tools($db); + $phpbb_root_path = __DIR__ . './../../phpBB/'; + $php_ext = 'php'; + $table_prefix = 'phpbb_'; + + return new phpbb_extension_manager( + new phpbb_mock_container_builder(), + $db, + $config, + new phpbb_db_migrator($config, $db, $db_tools, 'phpbb_migrations', $phpbb_root_path, $php_ext, $table_prefix, array()), + 'phpbb_ext', + dirname(__FILE__) . '/', + '.' . $php_ext, + ($with_cache) ? new phpbb_mock_cache() : null + ); + } } diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index ce7be0dea5..cdea8d5258 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -34,9 +34,11 @@ class metadata_manager_test extends phpbb_database_test_case 'version' => '3.1.0', )); $this->db = $this->new_dbal(); + $this->db_tools = new phpbb_db_tools($this->db); $this->phpbb_root_path = dirname(__FILE__) . '/'; $this->phpEx = '.php'; $this->user = new phpbb_user(); + $this->table_prefix = 'phpbb_'; $this->template = new phpbb_template( $this->phpbb_root_path, @@ -48,8 +50,10 @@ class metadata_manager_test extends phpbb_database_test_case ); $this->extension_manager = new phpbb_extension_manager( + new phpbb_mock_container_builder(), $this->db, $this->config, + new phpbb_db_migrator($this->config, $this->db, $this->db_tools, 'phpbb_migrations', $this->phpbb_root_path, $this->php_ext, $this->table_prefix, array()), 'phpbb_ext', $this->phpbb_root_path, $this->phpEx, diff --git a/tests/fixtures/empty.xml b/tests/fixtures/empty.xml index 96eb1ab483..195e30e38d 100644 --- a/tests/fixtures/empty.xml +++ b/tests/fixtures/empty.xml @@ -1,5 +1,9 @@ <?xml version="1.0" encoding="UTF-8" ?> <dataset> - <table name="phpbb_posts"> + <table name="phpbb_sessions"> + <column>session_id</column> + <column>session_user_id</column> + <column>session_ip</column> + <column>session_browser</column> </table> </dataset> diff --git a/tests/functional/acp_permissions_test.php b/tests/functional/acp_permissions_test.php new file mode 100644 index 0000000000..f7fd44fc89 --- /dev/null +++ b/tests/functional/acp_permissions_test.php @@ -0,0 +1,128 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case +{ + public function setUp() + { + parent::setUp(); + + $this->login(); + $this->admin_login(); + $this->add_lang('acp/permissions'); + } + + public function test_permissions_tab() + { + // Permissions tab + // XXX hardcoded id + $crawler = $this->request('GET', 'adm/index.php?i=16&sid=' . $this->sid); + $this->assert_response_success(); + // these language strings are html + $this->assertContains($this->lang('ACP_PERMISSIONS_EXPLAIN'), $this->client->getResponse()->getContent()); + } + + public function test_select_user() + { + // User permissions + $crawler = $this->request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid); + $this->assert_response_success(); + $this->assertContains($this->lang('ACP_USERS_PERMISSIONS_EXPLAIN'), $this->client->getResponse()->getContent()); + + // Select admin + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $data = array('username[0]' => 'admin'); + $form->setValues($data); + $crawler = $this->client->submit($form); + $this->assert_response_success(); + $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); + } + + public function permissions_data() + { + return array( + // description + // permission type + // permission name + // mode + // object name + // object id + array( + 'user permission', + 'u_', + 'u_hideonline', + 'setting_user_global', + 'user_id', + 2, + ), + array( + 'moderator permission', + 'm_', + 'm_ban', + 'setting_mod_global', + 'group_id', + 4, + ), + /* Admin does not work yet, probably because founder can do everything + array( + 'admin permission', + 'a_', + 'a_forum', + 'setting_admin_global', + 'group_id', + 5, + ), + */ + ); + } + + /** + * @dataProvider permissions_data + */ + public function test_change_permission($description, $permission_type, $permission, $mode, $object_name, $object_id) + { + // Get the form + $crawler = $this->request('GET', "adm/index.php?i=acp_permissions&icat=16&mode=$mode&${object_name}[0]=$object_id&type=$permission_type&sid=" . $this->sid); + $this->assert_response_success(); + $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); + + // XXX globals for phpbb_auth, refactor it later + global $db, $cache; + $db = $this->get_db(); + $cache = new phpbb_mock_null_cache; + + $auth = new phpbb_auth; + // XXX hardcoded id + $user_data = $auth->obtain_user_data(2); + $auth->acl($user_data); + $this->assertEquals(1, $auth->acl_get($permission)); + + // Set u_hideonline to never + $form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form(); + // initially it should be a yes + $values = $form->getValues(); + $this->assertEquals(1, $values["setting[$object_id][0][$permission]"]); + // set to never + $data = array("setting[$object_id][0][$permission]" => '0'); + $form->setValues($data); + $crawler = $this->client->submit($form); + $this->assert_response_success(); + $this->assertContains($this->lang('AUTH_UPDATED'), $crawler->text()); + + // check acl again + $auth = new phpbb_auth; + // XXX hardcoded id + $user_data = $auth->obtain_user_data(2); + $auth->acl($user_data); + $this->assertEquals(0, $auth->acl_get($permission)); + } +} diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php index e955dcb4df..f92a4a2210 100644 --- a/tests/functional/auth_test.php +++ b/tests/functional/auth_test.php @@ -18,9 +18,19 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case // check for logout link $crawler = $this->request('GET', 'index.php'); + $this->assert_response_success(); $this->assertContains($this->lang('LOGOUT_USER', 'admin'), $crawler->filter('.navbar')->text()); } + public function test_login_other() + { + $this->create_user('anothertestuser'); + $this->login('anothertestuser'); + $crawler = $this->request('GET', 'index.php'); + $this->assert_response_success(); + $this->assertContains('anothertestuser', $crawler->filter('.icon-logout')->text()); + } + /** * @depends test_login */ @@ -31,10 +41,23 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case // logout $crawler = $this->request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); + $this->assert_response_success(); $this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text()); // look for a register link, which should be visible only when logged out $crawler = $this->request('GET', 'index.php'); + $this->assert_response_success(); $this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text()); } + + public function test_acp_login() + { + $this->login(); + $this->admin_login(); + + // check that we are logged in + $crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid); + $this->assert_response_success(); + $this->assertContains($this->lang('ADMIN_PANEL'), $crawler->filter('h1')->text()); + } } diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index 99afcfdc3d..b663c89e95 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -44,8 +44,9 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case public function test_empty_file() { + $this->markTestIncomplete('Test fails intermittently.'); $crawler = $this->upload_file('empty.png', 'image/png'); - $this->assertEquals($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $crawler->filter('div#message p')->text()); + $this->assertEquals($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $this->assert_filter($crawler, 'div#message p')->text()); } public function test_invalid_extension() @@ -63,6 +64,7 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case public function test_valid_file() { + $this->markTestIncomplete('Test fails intermittently.'); $crawler = $this->upload_file('valid.jpg', 'image/jpeg'); $this->assert_response_success(); // ensure there was no error message rendered diff --git a/tests/functional/memberlist_test.php b/tests/functional/memberlist_test.php new file mode 100644 index 0000000000..879bee2f0e --- /dev/null +++ b/tests/functional/memberlist_test.php @@ -0,0 +1,43 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_memberlist_test extends phpbb_functional_test_case +{ + public function test_memberlist() + { + $this->create_user('memberlist-test-user'); + // logs in as admin + $this->login(); + $crawler = $this->request('GET', 'memberlist.php?sid=' . $this->sid); + $this->assert_response_success(); + $this->assertContains('memberlist-test-user', $crawler->text()); + + // restrict by first character + $crawler = $this->request('GET', 'memberlist.php?first_char=m&sid=' . $this->sid); + $this->assert_response_success(); + $this->assertContains('memberlist-test-user', $crawler->text()); + + // make sure results for wrong character are not returned + $crawler = $this->request('GET', 'memberlist.php?first_char=a&sid=' . $this->sid); + $this->assert_response_success(); + $this->assertNotContains('memberlist-test-user', $crawler->text()); + } + + public function test_viewprofile() + { + $this->login(); + // XXX hardcoded user id + $crawler = $this->request('GET', 'memberlist.php?mode=viewprofile&u=2&sid=' . $this->sid); + $this->assert_response_success(); + $this->assertContains('admin', $crawler->filter('h2')->text()); + } +} diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index f54a3591b2..d05207edf0 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -15,70 +15,93 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case public function test_post_new_topic() { $this->login(); - $this->add_lang('posting'); - $crawler = $this->request('GET', 'posting.php?mode=post&f=2&sid=' . $this->sid); - $this->assertContains($this->lang('POST_TOPIC'), $crawler->filter('html')->text()); + // Test creating topic + $post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.'); - $hidden_fields = array(); - $hidden_fields[] = $crawler->filter('[type="hidden"]')->each(function ($node, $i) { - return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); - }); + $crawler = $this->request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); + $this->assertContains('This is a test topic posted by the testing framework.', $crawler->filter('html')->text()); - $test_message = 'This is a test topic posted by the testing framework.'; - $form_data = array( - 'subject' => 'Test Topic 1', - 'message' => $test_message, - 'post' => true, - 'f' => 2, - 'mode' => 'post', - 'sid' => $this->sid, - ); + // Test creating a reply + $post2 = $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post posted by the testing framework.'); - foreach ($hidden_fields as $fields) - { - foreach($fields as $field) - { - $form_data[$field['name']] = $field['value']; - } - } + $crawler = $this->request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); + $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); - // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) - // is not at least 2 seconds before submission, cancel the form - $form_data['lastclick'] = 0; + // Test quoting a message + $crawler = $this->request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}"); + $this->assert_response_success(); + $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); + } - // I use a request because the form submission method does not allow you to send data that is not - // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) - // Instead, I send it as a request with the submit button "post" set to true. - $crawler = $this->client->request('POST', 'posting.php', $form_data); - $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); + /** + * Creates a topic + * + * Be sure to login before creating + * + * @param int $forum_id + * @param string $subject + * @param string $message + * @param array $additional_form_data Any additional form data to be sent in the request + * @return array post_id, topic_id + */ + public function create_topic($forum_id, $subject, $message, $additional_form_data = array()) + { + $posting_url = "posting.php?mode=post&f={$forum_id}&sid={$this->sid}"; + + $form_data = array_merge(array( + 'subject' => $subject, + 'message' => $message, + 'post' => true, + ), $additional_form_data); - $crawler = $this->request('GET', 'viewtopic.php?t=2&sid=' . $this->sid); - $this->assertContains($test_message, $crawler->filter('html')->text()); + return $this->submit_post($posting_url, 'POST_TOPIC', $form_data); } - public function test_post_reply() + /** + * Creates a post + * + * Be sure to login before creating + * + * @param int $forum_id + * @param string $subject + * @param string $message + * @param array $additional_form_data Any additional form data to be sent in the request + * @return array post_id, topic_id + */ + public function create_post($forum_id, $topic_id, $subject, $message, $additional_form_data = array()) { - $this->login(); - $this->add_lang('posting'); + $posting_url = "posting.php?mode=reply&f={$forum_id}&t={$topic_id}&sid={$this->sid}"; - $crawler = $this->request('GET', 'posting.php?mode=reply&t=2&f=2&sid=' . $this->sid); - $this->assertContains($this->lang('POST_REPLY'), $crawler->filter('html')->text()); + $form_data = array_merge(array( + 'subject' => $subject, + 'message' => $message, + 'post' => true, + ), $additional_form_data); - $hidden_fields = array(); - $hidden_fields[] = $crawler->filter('[type="hidden"]')->each(function ($node, $i) { - return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); - }); + return $this->submit_post($posting_url, 'POST_REPLY', $form_data); + } + + /** + * Helper for submitting posts + * + * @param string $posting_url + * @param string $posting_contains + * @param array $form_data + * @return array post_id, topic_id + */ + protected function submit_post($posting_url, $posting_contains, $form_data) + { + $this->add_lang('posting'); - $test_message = 'This is a test post posted by the testing framework.'; - $form_data = array( - 'subject' => 'Re: Test Topic 1', - 'message' => $test_message, - 'post' => true, - 't' => 2, - 'f' => 2, - 'mode' => 'reply', - 'sid' => $this->sid, + $crawler = $this->request('GET', $posting_url); + $this->assert_response_success(); + $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); + + $hidden_fields = array( + $crawler->filter('[type="hidden"]')->each(function ($node, $i) { + return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); + }), ); foreach ($hidden_fields as $fields) @@ -89,14 +112,28 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case } } - // For reasoning behind the following command, see the test_post_new_topic() test + // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) + // is not at least 2 seconds before submission, cancel the form $form_data['lastclick'] = 0; - // Submit the post - $crawler = $this->client->request('POST', 'posting.php', $form_data); + // I use a request because the form submission method does not allow you to send data that is not + // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) + // Instead, I send it as a request with the submit button "post" set to true. + $crawler = $this->client->request('POST', $posting_url, $form_data); + $this->assert_response_success(); $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); - $crawler = $this->request('GET', 'viewtopic.php?t=2&sid=' . $this->sid); - $this->assertContains($test_message, $crawler->filter('html')->text()); + $url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri(); + + $matches = $topic_id = $post_id = false; + preg_match_all('#&t=([0-9]+)(&p=([0-9]+))?#', $url, $matches); + + $topic_id = (int) (isset($matches[1][0])) ? $matches[1][0] : 0; + $post_id = (int) (isset($matches[3][0])) ? $matches[3][0] : 0; + + return array( + 'topic_id' => $topic_id, + 'post_id' => $post_id, + ); } } diff --git a/tests/functions/build_hidden_fields_for_query_params_test.php b/tests/functions/build_hidden_fields_for_query_params_test.php new file mode 100644 index 0000000000..ef2f5744d3 --- /dev/null +++ b/tests/functions/build_hidden_fields_for_query_params_test.php @@ -0,0 +1,71 @@ +<?php +/** +* +* @package testing +* @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'; + +class phpbb_build_hidden_fields_for_query_params_test extends phpbb_test_case +{ + public function build_hidden_fields_for_query_params_test_data() + { + return array( + // get + // post + // exclude + // expected + array( + array('foo' => 'bar'), + array(), + array(), + "<input type='hidden' name=\"foo\" value=\"bar\" />", + ), + array( + array('foo' => 'bar', 'a' => 'b'), + array(), + array(), + "<input type='hidden' name=\"foo\" value=\"bar\" /><input type='hidden' name=\"a\" value=\"b\" />", + ), + array( + array('a' => 'quote"', 'b' => '<less>'), + array(), + array(), + "<input type='hidden' name=\"a\" value='quote\"' /><input type='hidden' name=\"b\" value=\"<less>\" />", + ), + array( + array('a' => "quotes'\""), + array(), + array(), + "<input type='hidden' name=\"a\" value=\"quotes'"\" />", + ), + array( + array('foo' => 'bar', 'a' => 'b'), + array('a' => 'c'), + array(), + "<input type='hidden' name=\"foo\" value=\"bar\" />", + ), + // strict equality check + array( + array('foo' => 'bar', 'a' => '0'), + array('a' => ''), + array(), + "<input type='hidden' name=\"foo\" value=\"bar\" />", + ), + ); + } + + /** + * @dataProvider build_hidden_fields_for_query_params_test_data + */ + public function test_build_hidden_fields_for_query_params($get, $post, $exclude, $expected) + { + $request = new phpbb_mock_request($get, $post); + $result = phpbb_build_hidden_fields_for_query_params($request, $exclude); + + $this->assertEquals($expected, $result); + } +} diff --git a/tests/functions/convert_30_dbms_to_31_test.php b/tests/functions/convert_30_dbms_to_31_test.php new file mode 100644 index 0000000000..d08bf87f15 --- /dev/null +++ b/tests/functions/convert_30_dbms_to_31_test.php @@ -0,0 +1,40 @@ +<?php +/** +* +* @package testing +* @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'; + +class phpbb_convert_30_dbms_to_31_test extends phpbb_test_case +{ + public function convert_30_dbms_to_31_data() + { + return array( + array('firebird'), + array('mssql'), + array('mssql_odbc'), + array('mssqlnative'), + array('mysql'), + array('mysqli'), + array('oracle'), + array('postgres'), + array('sqlite'), + ); + } + + /** + * @dataProvider convert_30_dbms_to_31_data + */ + public function test_convert_30_dbms_to_31($input) + { + $expected = "phpbb_db_driver_$input"; + + $output = phpbb_convert_30_dbms_to_31($input); + + $this->assertEquals($expected, $output); + } +} diff --git a/tests/functions/quoteattr_test.php b/tests/functions/quoteattr_test.php new file mode 100644 index 0000000000..9d2a7d470e --- /dev/null +++ b/tests/functions/quoteattr_test.php @@ -0,0 +1,44 @@ +<?php +/** +* +* @package testing +* @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'; + +class phpbb_quoteattr_test extends phpbb_test_case +{ + public function quoteattr_test_data() + { + return array( + array('foo', null, '"foo"'), + array('', null, '""'), + array(' ', null, '" "'), + array('<a>', null, '"<a>"'), + array('&', null, '"&amp;"'), + array('"hello"', null, "'\"hello\"'"), + array("'hello'", null, "\"'hello'\""), + array("\"'", null, "\""'\""), + array("a\nb", null, '"a b"'), + array("a\r\nb", null, '"a b"'), + array("a\tb", null, '"a	b"'), + array('a b', null, '"a b"'), + array('"a<b"', null, "'\"a<b\"'"), + array('foo', array('f' => 'z'), '"zoo"'), + array('<a>', array('a' => '&'), '"<&>"'), + ); + } + + /** + * @dataProvider quoteattr_test_data + */ + public function test_quoteattr($input, $entities, $expected) + { + $output = phpbb_quoteattr($input, $entities); + + $this->assertEquals($expected, $output); + } +} diff --git a/tests/functions_database_helper/fixtures/bookmarks_duplicates.xml b/tests/functions_database_helper/fixtures/bookmarks_duplicates.xml new file mode 100644 index 0000000000..d49f76b073 --- /dev/null +++ b/tests/functions_database_helper/fixtures/bookmarks_duplicates.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_bookmarks"> + <column>user_id</column> + <column>topic_id</column> + + <!-- one entry for this topic --> + <row> + <value>1</value> + <value>1</value> + </row> + + <!-- non-conflicting entries --> + <row> + <value>2</value> + <value>2</value> + </row> + <row> + <value>3</value> + <value>3</value> + </row> + + <!-- conflicting entries --> + <row> + <value>1</value> + <value>4</value> + </row> + <row> + <value>1</value> + <value>5</value> + </row> + + <!-- conflicting and non-conflicting entries --> + <row> + <value>1</value> + <value>6</value> + </row> + <row> + <value>1</value> + <value>7</value> + </row> + <row> + <value>2</value> + <value>6</value> + </row> + </table> +</dataset> diff --git a/tests/functions_database_helper/fixtures/topics_watch_duplicates.xml b/tests/functions_database_helper/fixtures/topics_watch_duplicates.xml new file mode 100644 index 0000000000..c387bb737a --- /dev/null +++ b/tests/functions_database_helper/fixtures/topics_watch_duplicates.xml @@ -0,0 +1,80 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_topics_watch"> + <column>user_id</column> + <column>topic_id</column> + <column>notify_status</column> + + <!-- one entry for this topic --> + <row> + <value>1</value> + <value>1</value> + <value>1</value> + </row> + + <!-- non-conflicting entries --> + <row> + <value>1</value> + <value>2</value> + <value>1</value> + </row> + <row> + <value>2</value> + <value>3</value> + <value>0</value> + </row> + + <!-- conflicting entries, same notify status --> + <row> + <value>1</value> + <value>4</value> + <value>1</value> + </row> + <row> + <value>1</value> + <value>5</value> + <value>1</value> + </row> + + <!-- conflicting entries, notify status 0 into 1 --> + <row> + <value>1</value> + <value>6</value> + <value>0</value> + </row> + <row> + <value>1</value> + <value>7</value> + <value>1</value> + </row> + + <!-- conflicting entries, notify status 1 into 0 --> + <row> + <value>1</value> + <value>8</value> + <value>1</value> + </row> + <row> + <value>1</value> + <value>9</value> + <value>0</value> + </row> + + <!-- conflicting and non-conflicting entries --> + <row> + <value>1</value> + <value>10</value> + <value>0</value> + </row> + <row> + <value>1</value> + <value>11</value> + <value>1</value> + </row> + <row> + <value>2</value> + <value>10</value> + <value>1</value> + </row> + </table> +</dataset> diff --git a/tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php b/tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php new file mode 100644 index 0000000000..d4881daf7e --- /dev/null +++ b/tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php @@ -0,0 +1,101 @@ +<?php +/** +* +* @package testing +* @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_database_helper.php'; + +class phpbb_update_rows_avoiding_duplicates_notify_status_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/topics_watch_duplicates.xml'); + } + + public static function fixture_data() + { + return array( + // description + // from array + // to value + // expected count with to value post update + // expected notify_status values + array( + 'trivial', + array(1), + 1000, + 1, + 1, + ), + array( + 'no conflict', + array(2), + 3, + 2, + 1, + ), + array( + 'conflict, same notify status', + array(4), + 5, + 1, + 1, + ), + array( + 'conflict, notify status 0 into 1', + array(6), + 7, + 1, + 0, + ), + array( + 'conflict, notify status 1 into 0', + array(8), + 9, + 1, + 0, + ), + array( + 'conflict and no conflict', + array(10), + 11, + 2, + 0, + ), + ); + } + + /** + * @dataProvider fixture_data + */ + public function test_update($description, $from, $to, $expected_result_count, $expected_notify_status) + { + $db = $this->new_dbal(); + + phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', $from, $to); + + $sql = 'SELECT COUNT(*) AS remaining_rows + FROM ' . TOPICS_WATCH_TABLE . ' + WHERE topic_id = ' . (int) $to; + $result = $db->sql_query($sql); + $result_count = $db->sql_fetchfield('remaining_rows'); + $db->sql_freeresult($result); + + $this->assertEquals($expected_result_count, $result_count); + + // user id of 1 is the user being updated + $sql = 'SELECT notify_status + FROM ' . TOPICS_WATCH_TABLE . ' + WHERE topic_id = ' . (int) $to . ' + AND user_id = 1'; + $result = $db->sql_query($sql); + $notify_status = $db->sql_fetchfield('notify_status'); + $db->sql_freeresult($result); + + $this->assertEquals($expected_notify_status, $notify_status); + } +} diff --git a/tests/functions_database_helper/update_rows_avoiding_duplicates_test.php b/tests/functions_database_helper/update_rows_avoiding_duplicates_test.php new file mode 100644 index 0000000000..2f01d29d15 --- /dev/null +++ b/tests/functions_database_helper/update_rows_avoiding_duplicates_test.php @@ -0,0 +1,71 @@ +<?php +/** +* +* @package testing +* @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_database_helper.php'; + +class phpbb_update_rows_avoiding_duplicates_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/bookmarks_duplicates.xml'); + } + + public static function fixture_data() + { + return array( + // description + // from array + // to value + // expected count with to value post update + array( + 'trivial', + array(1), + 10, + 1, + ), + array( + 'no conflict', + array(2), + 3, + 2, + ), + array( + 'conflict', + array(4), + 5, + 1, + ), + array( + 'conflict and no conflict', + array(6), + 7, + 2, + ), + ); + } + + /** + * @dataProvider fixture_data + */ + public function test_update($description, $from, $to, $expected_result_count) + { + $db = $this->new_dbal(); + + phpbb_update_rows_avoiding_duplicates($db, BOOKMARKS_TABLE, 'topic_id', $from, $to); + + $sql = 'SELECT COUNT(*) AS remaining_rows + FROM ' . BOOKMARKS_TABLE . ' + WHERE topic_id = ' . (int) $to; + $result = $db->sql_query($sql); + $result_count = $db->sql_fetchfield('remaining_rows'); + $db->sql_freeresult($result); + + $this->assertEquals($expected_result_count, $result_count); + } +} diff --git a/tests/functions_user/fixtures/group_user_attributes.xml b/tests/functions_user/fixtures/group_user_attributes.xml new file mode 100644 index 0000000000..f4edbdca49 --- /dev/null +++ b/tests/functions_user/fixtures/group_user_attributes.xml @@ -0,0 +1,121 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_groups"> + <column>group_id</column> + <column>group_avatar</column> + <column>group_rank</column> + <column>group_desc</column> + <row> + <value>1</value> + <value>default</value> + <value>1</value> + <value></value> + </row> + <row> + <value>2</value> + <value></value> + <value>0</value> + <value></value> + </row> + <row> + <value>3</value> + <value>default2</value> + <value>3</value> + <value></value> + </row> + </table> + <table name="phpbb_users"> + <column>user_id</column> + <column>group_id</column> + <column>user_avatar</column> + <column>user_rank</column> + <column>username_clean</column> + <column>user_permissions</column> + <column>user_sig</column> + <column>user_occ</column> + <column>user_interests</column> + <row> + <value>1</value> + <value>1</value> + <value></value> + <value>0</value> + <value>barfoo</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>2</value> + <value>1</value> + <value>default</value> + <value>1</value> + <value>foobar</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>3</value> + <value>1</value> + <value>custom</value> + <value>2</value> + <value>bertie</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + </table> + <table name="phpbb_user_group"> + <column>user_id</column> + <column>group_id</column> + <column>user_pending</column> + <row> + <value>1</value> + <value>1</value> + <value>0</value> + </row> + <row> + <value>1</value> + <value>2</value> + <value>0</value> + </row> + <row> + <value>1</value> + <value>3</value> + <value>0</value> + </row> + <row> + <value>2</value> + <value>1</value> + <value>0</value> + </row> + <row> + <value>2</value> + <value>2</value> + <value>0</value> + </row> + <row> + <value>2</value> + <value>3</value> + <value>0</value> + </row> + <row> + <value>3</value> + <value>1</value> + <value>0</value> + </row> + <row> + <value>3</value> + <value>2</value> + <value>0</value> + </row> + <row> + <value>3</value> + <value>3</value> + <value>0</value> + </row> + </table> +</dataset> diff --git a/tests/functions_user/group_user_attributes_test.php b/tests/functions_user/group_user_attributes_test.php new file mode 100644 index 0000000000..f13156c2cc --- /dev/null +++ b/tests/functions_user/group_user_attributes_test.php @@ -0,0 +1,156 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2008 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/functions_user.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; + +class phpbb_functions_user_group_user_attributes_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/group_user_attributes.xml'); + } + + public function group_user_attributes_data() + { + return array( + array( + 'Setting new default group without settings for user with no settings - no change', + 1, + 2, + array( + 'group_avatar' => '', + 'group_avatar_type' => 0, + 'group_avatar_height' => 0, + 'group_avatar_width' => 0, + 'group_rank' => 0, + ), + array( + 'user_avatar' => '', + 'user_rank' => 0, + ), + ), + array( + 'Setting new default group without settings for user with default settings - user settings overwritten', + 2, + 2, + array( + 'group_avatar' => '', + 'group_avatar_type' => 0, + 'group_avatar_height' => 0, + 'group_avatar_width' => 0, + 'group_rank' => 0, + ), + array( + 'user_avatar' => '', + 'user_rank' => 0, + ), + ), + array( + 'Setting new default group without settings for user with custom settings - no change', + 3, + 2, + array( + 'group_avatar' => '', + 'group_avatar_type' => 0, + 'group_avatar_height' => 0, + 'group_avatar_width' => 0, + 'group_rank' => 0, + ), + array( + 'user_avatar' => 'custom', + 'user_rank' => 2, + ), + ), + array( + 'Setting new default group with settings for user with no settings - user settings overwritten', + 1, + 3, + array( + 'group_avatar' => 'default2', + 'group_avatar_type' => 1, + 'group_avatar_height' => 1, + 'group_avatar_width' => 1, + 'group_rank' => 3, + ), + array( + 'user_avatar' => 'default2', + 'user_rank' => 3, + ), + ), + array( + 'Setting new default group with settings for user with default settings - user settings overwritten', + 2, + 3, + array( + 'group_avatar' => 'default2', + 'group_avatar_type' => 1, + 'group_avatar_height' => 1, + 'group_avatar_width' => 1, + 'group_rank' => 3, + ), + array( + 'user_avatar' => 'default2', + 'user_rank' => 3, + ), + ), + array( + 'Setting new default group with settings for user with custom settings - no change', + 3, + 3, + array( + 'group_avatar' => 'default2', + 'group_avatar_type' => 1, + 'group_avatar_height' => 1, + 'group_avatar_width' => 1, + 'group_rank' => 3, + ), + array( + 'user_avatar' => 'custom', + 'user_rank' => 2, + ), + ), + ); + } + + /** + * @dataProvider group_user_attributes_data + */ + public function test_group_user_attributes($description, $user_id, $group_id, $group_row, $expected) + { + global $auth, $cache, $db, $phpbb_dispatcher, $user, $phpbb_container; + + $user->ip = ''; + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $auth = $this->getMock('phpbb_auth'); + $auth->expects($this->any()) + ->method('acl_clear_prefetch'); + $cache_driver = new phpbb_cache_driver_null(); + $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $phpbb_container + ->expects($this->any()) + ->method('get') + ->with('cache.driver') + ->will($this->returnValue($cache_driver)); + + group_user_attributes('default', $group_id, array($user_id), false, 'group_name', $group_row); + + $sql = 'SELECT user_avatar, user_rank + FROM ' . USERS_TABLE . ' + WHERE user_id = ' . $user_id; + $result = $db->sql_query($sql); + + $this->assertEquals(array($expected), $db->sql_fetchrowset($result)); + + $db->sql_freeresult($result); + } +} diff --git a/tests/mock/cache.php b/tests/mock/cache.php index bc18ca066b..71af3037f5 100644 --- a/tests/mock/cache.php +++ b/tests/mock/cache.php @@ -121,7 +121,11 @@ class phpbb_mock_cache implements phpbb_cache_driver_interface public function sql_load($query) { } - public function sql_save($query, $query_result, $ttl) + + /** + * {@inheritDoc} + */ + public function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl) { return $query_result; } diff --git a/tests/mock/filesystem_extension_manager.php b/tests/mock/filesystem_extension_manager.php new file mode 100644 index 0000000000..c5a51bbb3f --- /dev/null +++ b/tests/mock/filesystem_extension_manager.php @@ -0,0 +1,32 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_mock_filesystem_extension_manager extends phpbb_mock_extension_manager +{ + public function __construct($phpbb_root_path) + { + $extensions = array(); + $iterator = new DirectoryIterator($phpbb_root_path . 'ext/'); + foreach ($iterator as $fileinfo) + { + if ($fileinfo->isDir() && substr($fileinfo->getFilename(), 0, 1) != '.') + { + $name = $fileinfo->getFilename(); + $extension = array( + 'ext_name' => $name, + 'ext_active' => true, + 'ext_path' => 'ext/' . $name . '/', + ); + $extensions[$name] = $extension; + } + } + ksort($extensions); + parent::__construct($phpbb_root_path, $extensions); + } +} diff --git a/tests/mock/fileupload.php b/tests/mock/fileupload.php index 409036ba63..cbcbf4a6ab 100644 --- a/tests/mock/fileupload.php +++ b/tests/mock/fileupload.php @@ -20,33 +20,4 @@ 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( - 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/mock/null_cache.php b/tests/mock/null_cache.php new file mode 100644 index 0000000000..7bd33b441b --- /dev/null +++ b/tests/mock/null_cache.php @@ -0,0 +1,47 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_mock_null_cache +{ + public function __construct() + { + } + + public function get($var_name) + { + return false; + } + + public function put($var_name, $var, $ttl = 0) + { + } + + public function destroy($var_name, $table = '') + { + } + + public function obtain_bots() + { + return array(); + } + + public function obtain_word_list() + { + return array(); + } + + public function set_bots($bots) + { + } + + public function sql_exists($query_id) + { + return false; + } +} diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index 3ba3915714..3ad15bd806 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -26,7 +26,7 @@ class phpbb_search_mysql_test extends phpbb_search_common_test_case parent::setUp(); // dbal uses cache - $cache = new phpbb_cache_service(new phpbb_cache_driver_null); + $cache = new phpbb_mock_cache(); // set config values $config['fulltext_mysql_min_word_len'] = 4; diff --git a/tests/search/native_test.php b/tests/search/native_test.php index eeee3a44f3..4a2c210013 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -26,7 +26,7 @@ class phpbb_search_native_test extends phpbb_search_test_case parent::setUp(); // dbal uses cache - $cache = new phpbb_cache_service(new phpbb_cache_driver_null); + $cache = new phpbb_mock_cache(); $this->db = $this->new_dbal(); $error = null; diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index 9c77e0c09e..923af6f854 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -26,7 +26,7 @@ class phpbb_search_postgres_test extends phpbb_search_common_test_case parent::setUp(); // dbal uses cache - $cache = new phpbb_cache_service(new phpbb_cache_driver_null); + $cache = new phpbb_mock_cache(); // set config values $config['fulltext_postgres_min_word_len'] = 4; diff --git a/tests/session/append_sid_test.php b/tests/session/append_sid_test.php index 34f6dea8ca..b9e9ac1aa9 100644 --- a/tests/session/append_sid_test.php +++ b/tests/session/append_sid_test.php @@ -1,54 +1,54 @@ -<?php
-/**
-*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
-*
-*/
-
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
-
-class phpbb_session_append_sid_test extends phpbb_test_case
-{
-
- public function append_sid_data()
- {
- return array(
- array('viewtopic.php?t=1&f=2', false, true, false, 'viewtopic.php?t=1&f=2', 'parameters in url-argument'),
- array('viewtopic.php', 't=1&f=2', true, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument using amp'),
- array('viewtopic.php', 't=1&f=2', false, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument using &'),
- array('viewtopic.php', array('t' => 1, 'f' => 2), true, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument as array'),
-
- // Custom sid parameter
- array('viewtopic.php', 't=1&f=2', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid', 'using session_id'),
-
- // Testing anchors
- array('viewtopic.php?t=1&f=2#anchor', false, true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in url-argument'),
- array('viewtopic.php', 't=1&f=2#anchor', true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in params-argument'),
- array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in params-argument (array)'),
-
- // Anchors and custom sid
- array('viewtopic.php?t=1&f=2#anchor', false, true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in url-argument using session_id'),
- array('viewtopic.php', 't=1&f=2#anchor', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument using session_id'),
- array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'),
-
- // Empty parameters should not append the ?
- array('viewtopic.php', false, true, false, 'viewtopic.php', 'no params using bool false'),
- array('viewtopic.php', '', true, false, 'viewtopic.php', 'no params using empty string'),
- array('viewtopic.php', array(), true, false, 'viewtopic.php', 'no params using empty array'),
- );
- }
-
- /**
- * @dataProvider append_sid_data
- */
- public function test_append_sid($url, $params, $is_amp, $session_id, $expected, $description)
- {
- global $phpbb_dispatcher;
-
- $phpbb_dispatcher = new phpbb_mock_event_dispatcher;
- $this->assertEquals($expected, append_sid($url, $params, $is_amp, $session_id));
- }
-}
-
+<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_session_append_sid_test extends phpbb_test_case +{ + + public function append_sid_data() + { + return array( + array('viewtopic.php?t=1&f=2', false, true, false, 'viewtopic.php?t=1&f=2', 'parameters in url-argument'), + array('viewtopic.php', 't=1&f=2', true, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument using amp'), + array('viewtopic.php', 't=1&f=2', false, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument using &'), + array('viewtopic.php', array('t' => 1, 'f' => 2), true, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument as array'), + + // Custom sid parameter + array('viewtopic.php', 't=1&f=2', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid', 'using session_id'), + + // Testing anchors + array('viewtopic.php?t=1&f=2#anchor', false, true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in url-argument'), + array('viewtopic.php', 't=1&f=2#anchor', true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in params-argument'), + array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in params-argument (array)'), + + // Anchors and custom sid + array('viewtopic.php?t=1&f=2#anchor', false, true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in url-argument using session_id'), + array('viewtopic.php', 't=1&f=2#anchor', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument using session_id'), + array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + + // Empty parameters should not append the ? + array('viewtopic.php', false, true, false, 'viewtopic.php', 'no params using bool false'), + array('viewtopic.php', '', true, false, 'viewtopic.php', 'no params using empty string'), + array('viewtopic.php', array(), true, false, 'viewtopic.php', 'no params using empty array'), + ); + } + + /** + * @dataProvider append_sid_data + */ + public function test_append_sid($url, $params, $is_amp, $session_id, $expected, $description) + { + global $phpbb_dispatcher; + + $phpbb_dispatcher = new phpbb_mock_event_dispatcher; + $this->assertEquals($expected, append_sid($url, $params, $is_amp, $session_id)); + } +} + diff --git a/tests/session/testable_factory.php b/tests/session/testable_factory.php index cb85a01c5c..1e2b194ece 100644 --- a/tests/session/testable_factory.php +++ b/tests/session/testable_factory.php @@ -59,10 +59,10 @@ class phpbb_session_testable_factory /** * Retrieve the configured session class instance * - * @param dbal $dbal The database connection to use for session data + * @param phpbb_db_driver $dbal The database connection to use for session data * @return phpbb_mock_session_testable A session instance */ - public function get_session(dbal $dbal) + public function get_session(phpbb_db_driver $dbal) { // set up all the global variables used by session global $SID, $_SID, $db, $config, $cache, $request; diff --git a/tests/template/datasets/event_inheritance/ext/kappa/styles/all/template/test.html b/tests/template/datasets/event_inheritance/ext/kappa/styles/all/template/test.html new file mode 100644 index 0000000000..3eb906a09e --- /dev/null +++ b/tests/template/datasets/event_inheritance/ext/kappa/styles/all/template/test.html @@ -0,0 +1 @@ +Kappa test event in all diff --git a/tests/template/datasets/event_inheritance/ext/kappa/styles/silver/template/test.html b/tests/template/datasets/event_inheritance/ext/kappa/styles/silver/template/test.html new file mode 100644 index 0000000000..3b65d80a6d --- /dev/null +++ b/tests/template/datasets/event_inheritance/ext/kappa/styles/silver/template/test.html @@ -0,0 +1 @@ +Kappa test event in silver diff --git a/tests/template/datasets/event_inheritance/ext/kappa/styles/silver_inherit/template/test.html b/tests/template/datasets/event_inheritance/ext/kappa/styles/silver_inherit/template/test.html new file mode 100644 index 0000000000..26826d59e3 --- /dev/null +++ b/tests/template/datasets/event_inheritance/ext/kappa/styles/silver_inherit/template/test.html @@ -0,0 +1 @@ +Kappa test event in silver_inherit diff --git a/tests/template/datasets/event_inheritance/ext/omega/styles/all/template/test.html b/tests/template/datasets/event_inheritance/ext/omega/styles/all/template/test.html new file mode 100644 index 0000000000..003d193dc3 --- /dev/null +++ b/tests/template/datasets/event_inheritance/ext/omega/styles/all/template/test.html @@ -0,0 +1 @@ +Omega test event in all diff --git a/tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/test.html b/tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/test.html new file mode 100644 index 0000000000..6bf06f5457 --- /dev/null +++ b/tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/test.html @@ -0,0 +1 @@ +Omega test event in silver diff --git a/tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/two.html b/tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/two.html new file mode 100644 index 0000000000..7f8058f4e4 --- /dev/null +++ b/tests/template/datasets/event_inheritance/ext/omega/styles/silver/template/two.html @@ -0,0 +1 @@ +two in silver in omega diff --git a/tests/template/datasets/event_inheritance/ext/zeta/styles/all/template/test.html b/tests/template/datasets/event_inheritance/ext/zeta/styles/all/template/test.html new file mode 100644 index 0000000000..5fc7e5ac12 --- /dev/null +++ b/tests/template/datasets/event_inheritance/ext/zeta/styles/all/template/test.html @@ -0,0 +1 @@ +Zeta test event in all diff --git a/tests/template/datasets/event_inheritance/styles/silver/template/event_test.html b/tests/template/datasets/event_inheritance/styles/silver/template/event_test.html new file mode 100644 index 0000000000..4d78dddb12 --- /dev/null +++ b/tests/template/datasets/event_inheritance/styles/silver/template/event_test.html @@ -0,0 +1 @@ +<!-- EVENT test --> diff --git a/tests/template/datasets/event_inheritance/styles/silver/template/event_two.html b/tests/template/datasets/event_inheritance/styles/silver/template/event_two.html new file mode 100644 index 0000000000..fe46be3782 --- /dev/null +++ b/tests/template/datasets/event_inheritance/styles/silver/template/event_two.html @@ -0,0 +1 @@ +<!-- EVENT two --> diff --git a/tests/template/datasets/event_inheritance/styles/silver_inherit/template/event_test.html b/tests/template/datasets/event_inheritance/styles/silver_inherit/template/event_test.html new file mode 100644 index 0000000000..4d78dddb12 --- /dev/null +++ b/tests/template/datasets/event_inheritance/styles/silver_inherit/template/event_test.html @@ -0,0 +1 @@ +<!-- EVENT test --> diff --git a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/universal.html b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/universal.html new file mode 100644 index 0000000000..f2c5762ade --- /dev/null +++ b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/universal.html @@ -0,0 +1 @@ +Universal in trivial extension. diff --git a/tests/template/datasets/ext_trivial/ext/trivial/styles/silver/template/simple.html b/tests/template/datasets/ext_trivial/ext/trivial/styles/silver/template/simple.html new file mode 100644 index 0000000000..fe32a1ed3f --- /dev/null +++ b/tests/template/datasets/ext_trivial/ext/trivial/styles/silver/template/simple.html @@ -0,0 +1 @@ +Simple in trivial extension. diff --git a/tests/template/datasets/ext_trivial/styles/silver/template/event_simple.html b/tests/template/datasets/ext_trivial/styles/silver/template/event_simple.html new file mode 100644 index 0000000000..604c1acdce --- /dev/null +++ b/tests/template/datasets/ext_trivial/styles/silver/template/event_simple.html @@ -0,0 +1 @@ +<!-- EVENT simple --> diff --git a/tests/template/datasets/ext_trivial/styles/silver/template/event_universal.html b/tests/template/datasets/ext_trivial/styles/silver/template/event_universal.html new file mode 100644 index 0000000000..15425cacc3 --- /dev/null +++ b/tests/template/datasets/ext_trivial/styles/silver/template/event_universal.html @@ -0,0 +1 @@ +<!-- EVENT universal --> diff --git a/tests/template/includephp_test.php b/tests/template/includephp_test.php index c93a53e2ad..f1012b6939 100644 --- a/tests/template/includephp_test.php +++ b/tests/template/includephp_test.php @@ -48,7 +48,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case $this->setup_engine(array('tpl_allow_php' => true)); - $this->style->set_custom_style('tests', $cache_dir, ''); + $this->style->set_custom_style('tests', $cache_dir, array(), ''); $cache_file = $this->template->cachepath . 'includephp_absolute.html.php'; $this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php", $cache_file); diff --git a/tests/template/template_compile_test.php b/tests/template/template_compile_test.php index 0cfcd6ceb5..7393fc1747 100644 --- a/tests/template/template_compile_test.php +++ b/tests/template/template_compile_test.php @@ -16,7 +16,7 @@ class phpbb_template_template_compile_test extends phpbb_test_case protected function setUp() { - $this->template_compile = new phpbb_template_compile(false, null, ''); + $this->template_compile = new phpbb_template_compile(false, null, $this->style_resource_locator, ''); $this->template_path = dirname(__FILE__) . '/templates'; } diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php new file mode 100644 index 0000000000..6cea9b92e3 --- /dev/null +++ b/tests/template/template_events_test.php @@ -0,0 +1,118 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/template_test_case.php'; + +class phpbb_template_template_events_test extends phpbb_template_template_test_case +{ + public function template_data() + { + return array( + /* + array( + '', // file + '', // dataset + array(), // style names + array(), // vars + array(), // block vars + array(), // destroy + '', // expected result + ), + */ + array( + 'Simple template event', + 'ext_trivial', + array(), + 'event_simple.html', + array(), + array(), + array(), + "Simple in trivial extension.", + ), + array( + 'Universal template event ("all" style)', + 'ext_trivial', + array(), + 'event_universal.html', + array(), + array(), + array(), + "Universal in trivial extension.", + ), + array( + 'Template event with inheritance - parent', + 'event_inheritance', + array('silver'), + 'event_test.html', + array(), + array(), + array(), +'Kappa test event in all +Omega test event in all +Zeta test event in all +Kappa test event in silver +Omega test event in silver', + ), + array( + 'Template event with inheritance - child', + 'event_inheritance', + array('silver_inherit', 'silver'), + 'event_test.html', + array(), + array(), + array(), +'Kappa test event in all +Omega test event in all +Zeta test event in all +Kappa test event in silver_inherit', + ), + array( + 'Definition in parent style', + 'event_inheritance', + array('silver_inherit', 'silver'), + 'event_two.html', + array(), + array(), + array(), +'two in silver in omega', + ), + ); + } + + /** + * @dataProvider template_data + */ + public function test_event($desc, $dataset, $style_names, $file, array $vars, array $block_vars, array $destroy, $expected) + { + // Reset the engine state + $this->setup_engine_for_events($dataset, $style_names); + + // Run test + $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php'; + $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); + } + + protected function setup_engine_for_events($dataset, $style_names, array $new_config = array()) + { + global $phpbb_root_path, $phpEx, $user; + + $defaults = $this->config_defaults(); + $config = new phpbb_config(array_merge($defaults, $new_config)); + + $this->template_path = dirname(__FILE__) . "/datasets/$dataset/styles/silver/template"; + $this->style_resource_locator = new phpbb_style_resource_locator(); + $this->extension_manager = new phpbb_mock_filesystem_extension_manager( + dirname(__FILE__) . "/datasets/$dataset/" + ); + $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context, $this->extension_manager); + $this->style_provider = new phpbb_style_path_provider(); + $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); + $this->style->set_custom_style('silver', array($this->template_path), $style_names, ''); + } +} diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 83995cb4ac..f43157775a 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -196,7 +196,25 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())), array('loop'), '', - ),/* no top level nested loops + ), + /* Currently fail on develop: + http://tracker.phpbb.com/browse/PHPBB3-11323 + array( + 'include_define_variable.html', + array('VARIABLE' => 'variable.html'), + array(), + array(), + 'variable.html', + ), + array( + 'include_loop_define.html', + array('VARIABLE' => 'value'), + array('loop' => array(array('NESTED_FILE' => 'variable.html'))), + array(), + 'value', + ), + */ + /* no top level nested loops array( 'loop_vars.html', array(), diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index 2e6f703eb1..3c997cb00e 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -69,7 +69,7 @@ class phpbb_template_template_test_case extends phpbb_test_case $this->style_provider = new phpbb_style_path_provider(); $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context()); $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); - $this->style->set_custom_style('tests', $this->template_path, ''); + $this->style->set_custom_style('tests', $this->template_path, array(), ''); } protected function setUp() diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php index 6a226f317a..7585be5728 100644 --- a/tests/template/template_test_case_with_tree.php +++ b/tests/template/template_test_case_with_tree.php @@ -24,6 +24,6 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat $this->style_provider = new phpbb_style_path_provider(); $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context()); $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); - $this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), ''); + $this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), array(), ''); } } diff --git a/tests/template/templates/events.html b/tests/template/templates/events.html new file mode 100644 index 0000000000..c44a7469e7 --- /dev/null +++ b/tests/template/templates/events.html @@ -0,0 +1,4 @@ +<!-- EVENT child_only --> +<!-- EVENT parent_only --> +<!-- EVENT parent_and_child --> +<!-- EVENT random_event --> diff --git a/tests/template/templates/include_define_variable.html b/tests/template/templates/include_define_variable.html new file mode 100644 index 0000000000..aff9b574c2 --- /dev/null +++ b/tests/template/templates/include_define_variable.html @@ -0,0 +1,2 @@ +<!-- DEFINE $DEF = '{VARIABLE}' --> +<!-- INCLUDE {$DEF} --> diff --git a/tests/template/templates/include_loop_define.html b/tests/template/templates/include_loop_define.html new file mode 100644 index 0000000000..f539b21396 --- /dev/null +++ b/tests/template/templates/include_loop_define.html @@ -0,0 +1,4 @@ +<!-- BEGIN loop --> +<!-- DEFINE $DEF = '{loop.NESTED_FILE}' --> +<!-- INCLUDE {$DEF} --> +<!-- END loop --> diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index b5076b92e9..72bce2e38a 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -49,7 +49,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 - if ($db_config['dbms'] == 'firebird') + if ($db_config['dbms'] == 'phpbb_db_driver_firebird') { $xml_data = file_get_contents($path); $xml_data = preg_replace_callback('/(?:(<table name="))([a-z_]+)(?:(">))/', 'phpbb_database_test_case::to_upper', $xml_data); @@ -118,9 +118,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $config = $this->get_database_config(); - require_once dirname(__FILE__) . '/../../phpBB/includes/db/' . $config['dbms'] . '.php'; - $dbal = 'dbal_' . $config['dbms']; - $db = new $dbal(); + $db = new $config['dbms'](); $db->sql_connect($config['dbhost'], $config['dbuser'], $config['dbpasswd'], $config['dbname'], $config['dbport']); return $db; diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index d7c2804aa7..29058cc815 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -108,7 +108,7 @@ 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 (!empty($this->config['custom_dsn']) && ($this->config['dbms'] == 'mssql' || $this->config['dbms'] == 'firebird')) + if (!empty($this->config['custom_dsn']) && ($this->config['dbms'] == 'phpbb_db_driver_mssql' || $this->config['dbms'] == 'phpbb_db_driver_firebird')) { $dsn = 'odbc:' . $this->config['custom_dsn']; } @@ -117,12 +117,12 @@ class phpbb_database_test_connection_manager { switch ($this->config['dbms']) { - case 'mssql': - case 'mssql_odbc': + case 'phpbb_db_driver_mssql': + case 'phpbb_db_driver_mssql_odbc': $this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('mssql', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']); break; - case 'firebird': + case 'phpbb_db_driver_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']); @@ -165,8 +165,8 @@ class phpbb_database_test_connection_manager { switch ($this->config['dbms']) { - case 'sqlite': - case 'firebird': + case 'phpbb_db_driver_sqlite': + case 'phpbb_db_driver_firebird': $this->connect(); // Drop all of the tables foreach ($this->get_tables() as $table) @@ -176,7 +176,7 @@ class phpbb_database_test_connection_manager $this->purge_extras(); break; - case 'oracle': + case 'phpbb_db_driver_oracle': $this->connect(); // Drop all of the tables foreach ($this->get_tables() as $table) @@ -186,6 +186,16 @@ class phpbb_database_test_connection_manager $this->purge_extras(); break; + case 'phpbb_db_driver_postgres': + $this->connect(); + // Drop all of the tables + foreach ($this->get_tables() as $table) + { + $this->pdo->exec('DROP TABLE ' . $table . ' CASCADE'); + } + $this->purge_extras(); + break; + default: $this->connect(false); @@ -226,39 +236,38 @@ class phpbb_database_test_connection_manager switch ($this->config['dbms']) { - case 'mysql': - case 'mysql4': - case 'mysqli': + case 'phpbb_db_driver_mysql': + case 'phpbb_db_driver_mysqli': $sql = 'SHOW TABLES'; break; - case 'sqlite': + case 'phpbb_db_driver_sqlite': $sql = 'SELECT name FROM sqlite_master WHERE type = "table"'; break; - case 'mssql': - case 'mssql_odbc': - case 'mssqlnative': + case 'phpbb_db_driver_mssql': + case 'phpbb_db_driver_mssql_odbc': + case 'phpbb_db_driver_mssqlnative': $sql = "SELECT name FROM sysobjects WHERE type='U'"; break; - case 'postgres': + case 'phpbb_db_driver_postgres': $sql = 'SELECT relname FROM pg_stat_user_tables'; break; - case 'firebird': + case 'phpbb_db_driver_firebird': $sql = 'SELECT rdb$relation_name FROM rdb$relations WHERE rdb$view_source is null AND rdb$system_flag = 0'; break; - case 'oracle': + case 'phpbb_db_driver_oracle': $sql = 'SELECT table_name FROM USER_TABLES'; break; @@ -293,8 +302,8 @@ class phpbb_database_test_connection_manager protected function load_schema_from_file($directory) { $schema = $this->dbms['SCHEMA']; - - if ($this->config['dbms'] == 'mysql') + + if ($this->config['dbms'] == 'phpbb_db_driver_mysql') { $sth = $this->pdo->query('SELECT VERSION() AS version'); $row = $sth->fetch(PDO::FETCH_ASSOC); @@ -313,7 +322,7 @@ class phpbb_database_test_connection_manager $queries = file_get_contents($filename); $sql = phpbb_remove_comments($queries); - + $sql = split_sql_file($sql, $this->dbms['DELIM']); foreach ($sql as $query) @@ -328,47 +337,47 @@ class phpbb_database_test_connection_manager protected function get_dbms_data($dbms) { $available_dbms = array( - 'firebird' => array( + 'phpbb_db_driver_firebird' => array( 'SCHEMA' => 'firebird', 'DELIM' => ';;', 'PDO' => 'firebird', ), - 'mysqli' => array( + 'phpbb_db_driver_mysqli' => array( 'SCHEMA' => 'mysql_41', 'DELIM' => ';', 'PDO' => 'mysql', ), - 'mysql' => array( + 'phpbb_db_driver_mysql' => array( 'SCHEMA' => 'mysql', 'DELIM' => ';', 'PDO' => 'mysql', ), - 'mssql' => array( + 'phpbb_db_driver_mssql' => array( 'SCHEMA' => 'mssql', 'DELIM' => 'GO', 'PDO' => 'odbc', ), - 'mssql_odbc'=> array( + 'phpbb_db_driver_mssql_odbc'=> array( 'SCHEMA' => 'mssql', 'DELIM' => 'GO', 'PDO' => 'odbc', ), - 'mssqlnative' => array( + 'phpbb_db_driver_mssqlnative' => array( 'SCHEMA' => 'mssql', 'DELIM' => 'GO', 'PDO' => 'sqlsrv', ), - 'oracle' => array( + 'phpbb_db_driver_oracle' => array( 'SCHEMA' => 'oracle', 'DELIM' => '/', 'PDO' => 'oci', ), - 'postgres' => array( + 'phpbb_db_driver_postgres' => array( 'SCHEMA' => 'postgres', 'DELIM' => ';', 'PDO' => 'pgsql', ), - 'sqlite' => array( + 'phpbb_db_driver_sqlite' => array( 'SCHEMA' => 'sqlite', 'DELIM' => ';', 'PDO' => 'sqlite2', @@ -397,7 +406,7 @@ class phpbb_database_test_connection_manager switch ($this->config['dbms']) { - case 'firebird': + case 'phpbb_db_driver_firebird': $sql = 'SELECT RDB$GENERATOR_NAME FROM RDB$GENERATORS WHERE RDB$SYSTEM_FLAG = 0'; @@ -409,7 +418,7 @@ class phpbb_database_test_connection_manager } break; - case 'oracle': + case 'phpbb_db_driver_oracle': $sql = 'SELECT sequence_name FROM USER_SEQUENCES'; $result = $this->pdo->query($sql); @@ -419,6 +428,19 @@ class phpbb_database_test_connection_manager $queries[] = 'DROP SEQUENCE ' . current($row); } break; + + case 'phpbb_db_driver_postgres': + $sql = 'SELECT sequence_name + FROM information_schema.sequences'; + $result = $this->pdo->query($sql); + + while ($row = $result->fetch(PDO::FETCH_NUM)) + { + $queries[] = 'DROP SEQUENCE ' . current($row); + } + + $queries[] = 'DROP TYPE IF EXISTS varchar_ci CASCADE'; + break; } foreach ($queries as $query) @@ -444,7 +466,7 @@ class phpbb_database_test_connection_manager switch ($this->config['dbms']) { - case 'oracle': + case 'phpbb_db_driver_oracle': // Get all of the information about the sequences $sql = "SELECT t.table_name, tc.column_name, d.referenced_name as sequence_name, s.increment_by, s.min_value FROM USER_TRIGGERS t @@ -486,7 +508,7 @@ class phpbb_database_test_connection_manager } break; - case 'postgres': + case 'phpbb_db_driver_postgres': // Get the sequences attached to the tables $sql = 'SELECT column_name, table_name FROM information_schema.columns WHERE table_name IN (' . implode(', ', $table_names) . ") diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 16e1ccaff9..b570b464e6 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -34,13 +34,36 @@ class phpbb_functional_test_case extends phpbb_test_case static protected $config = array(); static protected $already_installed = false; - public function setUp() + static public function setUpBeforeClass() { + parent::setUpBeforeClass(); + + self::$config = phpbb_test_case_helpers::get_test_config(); + + // Important: this is used both for installation and by + // test cases for querying the tables. + // Therefore table prefix must be set before a board is + // installed, and also before each test case is run. + self::$config['table_prefix'] = 'phpbb_'; + if (!isset(self::$config['phpbb_functional_url'])) { - $this->markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.'); + self::markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.'); } + if (!self::$already_installed) + { + self::install_board(); + self::$already_installed = true; + } + } + + public function setUp() + { + parent::setUp(); + + $this->bootstrap(); + $this->cookieJar = new CookieJar; $this->client = new Goutte\Client(array(), null, $this->cookieJar); // Reset the curl handle because it is 0 at this point and not a valid @@ -73,27 +96,16 @@ class phpbb_functional_test_case extends phpbb_test_case $this->backupStaticAttributesBlacklist += array( 'phpbb_functional_test_case' => array('config', 'already_installed'), ); - - if (!static::$already_installed) - { - $this->install_board(); - $this->bootstrap(); - static::$already_installed = true; - } } protected function get_db() { global $phpbb_root_path, $phpEx; // so we don't reopen an open connection - if (!($this->db instanceof dbal)) + if (!($this->db instanceof phpbb_db_driver)) { - if (!class_exists('dbal_' . self::$config['dbms'])) - { - include($phpbb_root_path . 'includes/db/' . self::$config['dbms'] . ".$phpEx"); - } - $sql_db = 'dbal_' . self::$config['dbms']; - $this->db = new $sql_db(); + $dbms = self::$config['dbms']; + $this->db = new $dbms(); $this->db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport']); } return $this->db; @@ -122,34 +134,27 @@ class phpbb_functional_test_case extends phpbb_test_case { global $phpbb_root_path, $phpEx; - if (!$this->extension_manager) - { - $this->extension_manager = new phpbb_extension_manager( - $this->get_db(), - new phpbb_config(array()), - self::$config['table_prefix'] . 'ext', - $phpbb_root_path, - ".$phpEx", - $this->get_cache_driver() - ); - } - - return $this->extension_manager; + $config = new phpbb_config(array()); + $db = $this->get_db(); + $db_tools = new phpbb_db_tools($db); + + return new phpbb_extension_manager( + new phpbb_mock_container_builder(), + $db, + $config, + new phpbb_db_migrator($config, $db, $db_tools, self::$config['table_prefix'] . 'migrations', $phpbb_root_path, $php_ext, self::$config['table_prefix'], array()), + self::$config['table_prefix'] . 'ext', + dirname(__FILE__) . '/', + '.' . $php_ext, + $this->get_cache_driver() + ); } - protected function install_board() + static protected function install_board() { global $phpbb_root_path, $phpEx; - self::$config = phpbb_test_case_helpers::get_test_config(); - - if (!isset(self::$config['phpbb_functional_url'])) - { - return; - } - - self::$config['table_prefix'] = 'phpbb_'; - $this->recreate_database(self::$config); + self::recreate_database(self::$config); if (file_exists($phpbb_root_path . "config.$phpEx")) { @@ -194,19 +199,30 @@ class phpbb_functional_test_case extends phpbb_test_case )); // end data - $content = $this->do_request('install'); - $this->assertContains('Welcome to Installation', $content); - - $this->do_request('create_table', $data); - - $this->do_request('config_file', $data); + $content = self::do_request('install'); + self::assertNotSame(false, $content); + self::assertContains('Welcome to Installation', $content); + + // Installer uses 3.0-style dbms name + $data['dbms'] = str_replace('phpbb_db_driver_', '', $data['dbms']); + $content = self::do_request('create_table', $data); + self::assertNotSame(false, $content); + self::assertContains('The database tables used by phpBB', $content); + // 3.0 or 3.1 + self::assertContains('have been created and populated with some initial data.', $content); + + $content = self::do_request('config_file', $data); + self::assertNotSame(false, $content); + self::assertContains('Configuration file', $content); file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], true, true)); - $this->do_request('final', $data); + $content = self::do_request('final', $data); + self::assertNotSame(false, $content); + self::assertContains('You have successfully installed', $content); copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); } - private function do_request($sub, $post_data = null) + static private function do_request($sub, $post_data = null) { $context = null; @@ -225,13 +241,70 @@ class phpbb_functional_test_case extends phpbb_test_case return file_get_contents(self::$config['phpbb_functional_url'] . 'install/index.php?mode=install&sub=' . $sub, false, $context); } - private function recreate_database($config) + static private function recreate_database($config) { $db_conn_mgr = new phpbb_database_test_connection_manager($config); $db_conn_mgr->recreate_db(); } - protected function login() + /** + * Creates a new user with limited permissions + * + * @param string $username Also doubles up as the user's password + * @return int ID of created user + */ + protected function create_user($username) + { + // Required by unique_id + global $config; + + $config = new phpbb_config(array()); + $config['rand_seed'] = ''; + $config['rand_seed_last_update'] = time() + 600; + + // Required by user_add + global $db, $cache, $phpbb_dispatcher, $phpbb_container; + $db = $this->get_db(); + if (!function_exists('phpbb_mock_null_cache')) + { + require_once(__DIR__ . '/../mock/null_cache.php'); + } + $cache = new phpbb_mock_null_cache; + + $cache_driver = new phpbb_cache_driver_null(); + $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $phpbb_container + ->expects($this->any()) + ->method('get') + ->with('cache.driver') + ->will($this->returnValue($cache_driver)); + + if (!function_exists('utf_clean_string')) + { + require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php'); + } + if (!function_exists('user_add')) + { + require_once(__DIR__ . '/../../phpBB/includes/functions_user.php'); + } + set_config(null, null, null, $config); + set_config_count(null, null, null, $config); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + + $user_row = array( + 'username' => $username, + 'group_id' => 2, + 'user_email' => 'nobody@example.com', + 'user_type' => 0, + 'user_lang' => 'en', + 'user_timezone' => 0, + 'user_dateformat' => '', + 'user_password' => phpbb_hash($username), + ); + return user_add($user_row); + } + + protected function login($username = 'admin') { $this->add_lang('ucp'); @@ -239,7 +312,9 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text()); $form = $crawler->selectButton($this->lang('LOGIN'))->form(); - $login = $this->client->submit($form, array('username' => 'admin', 'password' => 'admin')); + $crawler = $this->client->submit($form, array('username' => $username, 'password' => $username)); + $this->assert_response_success(); + $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); $cookies = $this->cookieJar->all(); @@ -257,7 +332,7 @@ class phpbb_functional_test_case extends phpbb_test_case * Login to the ACP * You must run login() before calling this. */ - protected function admin_login() + protected function admin_login($username = 'admin') { $this->add_lang('acp/common'); @@ -277,7 +352,9 @@ class phpbb_functional_test_case extends phpbb_test_case { if (strpos($field, 'password_') === 0) { - $login = $this->client->submit($form, array('username' => 'admin', $field => 'admin')); + $crawler = $this->client->submit($form, array('username' => $username, $field => $username)); + $this->assert_response_success(); + $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); $cookies = $this->cookieJar->all(); @@ -358,4 +435,20 @@ class phpbb_functional_test_case extends phpbb_test_case $content = $this->client->getResponse()->getContent(); $this->assertNotContains('Fatal error:', $content); } + + public function assert_filter($crawler, $expr, $msg = null) + { + $nodes = $crawler->filter($expr); + if ($msg) + { + $msg .= "\n"; + } + else + { + $msg = ''; + } + $msg .= "`$expr` not found in DOM."; + $this->assertGreaterThan(0, count($nodes), $msg); + return $nodes; + } } diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index fe15eded90..20ae384f21 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -54,7 +54,7 @@ class phpbb_test_case_helpers if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>=')) { $config = array_merge($config, array( - 'dbms' => 'sqlite', + 'dbms' => 'phpbb_db_driver_sqlite', 'dbhost' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite2', // filename 'dbport' => '', 'dbname' => '', @@ -77,8 +77,13 @@ class phpbb_test_case_helpers { include($test_config); + if (!function_exists('phpbb_convert_30_dbms_to_31')) + { + require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + } + $config = array_merge($config, array( - 'dbms' => $dbms, + 'dbms' => phpbb_convert_30_dbms_to_31($dbms), 'dbhost' => $dbhost, 'dbport' => $dbport, 'dbname' => $dbname, @@ -104,8 +109,13 @@ class phpbb_test_case_helpers if (isset($_SERVER['PHPBB_TEST_DBMS'])) { + if (!function_exists('phpbb_convert_30_dbms_to_31')) + { + require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + } + $config = array_merge($config, array( - 'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $_SERVER['PHPBB_TEST_DBMS'] : '', + 'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? phpbb_convert_30_dbms_to_31($_SERVER['PHPBB_TEST_DBMS']) : '', 'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '', 'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '', 'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '', diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index c7ff2e78e0..87cd00197f 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -205,8 +205,7 @@ class phpbb_filespec_test extends phpbb_test_case */ public function test_get_extension($filename, $expected) { - $filespec = $this->get_filespec(); - $this->assertEquals($expected, $filespec->get_extension($filename)); + $this->assertEquals($expected, filespec::get_extension($filename)); } public function is_image_variables() |