diff options
132 files changed, 3088 insertions, 748 deletions
diff --git a/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php b/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php index ba2b40ecba..68e9e6bb86 100644 --- a/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php +++ b/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php @@ -35,7 +35,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff * @param int $stackPtr The position of the current token * in the stack passed in $tokens. * - * @return void + * @return null */ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { @@ -120,7 +120,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff * @param integer The stack pointer for the first comment token. * @param array(string=>array) $tags The found file doc comment tags. * - * @return void + * @return null */ protected function processPackage(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) { @@ -143,7 +143,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff * @param integer The stack pointer for the first comment token. * @param array(string=>array) $tags The found file doc comment tags. * - * @return void + * @return null */ protected function processVersion(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) { @@ -166,7 +166,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff * @param integer The stack pointer for the first comment token. * @param array(string=>array) $tags The found file doc comment tags. * - * @return void + * @return null */ protected function processCopyright(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) { @@ -189,7 +189,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff * @param integer The stack pointer for the first comment token. * @param array(string=>array) $tags The found file doc comment tags. * - * @return void + * @return null */ protected function processLicense(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) { diff --git a/phpBB/adm/style/ajax.js b/phpBB/adm/style/ajax.js index a3a77df89b..3ccb368665 100644 --- a/phpBB/adm/style/ajax.js +++ b/phpBB/adm/style/ajax.js @@ -36,7 +36,7 @@ phpbb.add_ajax_callback('row_down', function() { overlay: false }); - tr_swap.find('.up').html(img_templates.up_disabled); + tr_swap.find('.up').html(img_templates.up_disabled.clone()); } tr.insertAfter(tr_swap); @@ -48,7 +48,7 @@ phpbb.add_ajax_callback('row_down', function() { */ if (tr.is(':last-child')) { - tr.find('.down').html(img_templates.down_disabled); + tr.find('.down').html(img_templates.down_disabled.clone()); var down_img = img_templates.down.clone().attr('href', tr_swap.attr('data-down')); tr_swap.find('.down').html(down_img); @@ -82,7 +82,7 @@ phpbb.add_ajax_callback('row_up', function() { overlay: false }); - tr_swap.find('.down').html(img_templates.down_disabled); + tr_swap.find('.down').html(img_templates.down_disabled.clone()); } tr.insertBefore(tr_swap); @@ -94,7 +94,7 @@ phpbb.add_ajax_callback('row_up', function() { */ if (tr.is(':first-child')) { - tr.find('.up').html(img_templates.up_disabled); + tr.find('.up').html(img_templates.up_disabled.clone()); var up_img = img_templates.up.clone().attr('href', tr_swap.attr('data-up')); tr_swap.find('.up').html(up_img); diff --git a/phpBB/app.php b/phpBB/app.php new file mode 100644 index 0000000000..d93208d585 --- /dev/null +++ b/phpBB/app.php @@ -0,0 +1,31 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +*/ + +/** +* @ignore +*/ +define('IN_PHPBB', true); +$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './'; +$phpEx = substr(strrchr(__FILE__, '.'), 1); +include($phpbb_root_path . 'common.' . $phpEx); +include($phpbb_root_path . 'includes/functions_url_matcher.' . $phpEx); + +// Start session management +$user->session_begin(); +$auth->acl($user->data); +$user->setup('app'); + +$symfony_request = phpbb_create_symfony_request($request); +$http_kernel = $phpbb_container->get('http_kernel'); +$response = $http_kernel->handle($symfony_request); +$response->send(); +$http_kernel->terminate($symfony_request, $response); diff --git a/phpBB/common.php b/phpBB/common.php index c4237dfcf5..e99b9edee5 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -8,10 +8,6 @@ * Minimum Requirement: PHP 5.3.3 */ -use Symfony\Component\Config\FileLocator; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; - /** */ if (!defined('IN_PHPBB')) @@ -95,6 +91,7 @@ $phpbb_container = phpbb_create_dumped_container_unless_debug( ), array( new phpbb_di_pass_collection_pass(), + new phpbb_di_pass_kernel_pass(), ), $phpbb_root_path, $phpEx diff --git a/phpBB/composer.json b/phpBB/composer.json index 380bdc367c..d2536a73cf 100644 --- a/phpBB/composer.json +++ b/phpBB/composer.json @@ -5,9 +5,10 @@ "symfony/dependency-injection": "2.1.*", "symfony/event-dispatcher": "2.1.*", "symfony/http-kernel": "2.1.*", + "symfony/routing": "2.1.*", "symfony/yaml": "2.1.*" }, "require-dev": { - "fabpot/goutte": "1.0.x-dev" + "fabpot/goutte": "v0.1.0" } } diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 69e4a2b4b8..e96c15fe8b 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -1,5 +1,5 @@ { - "hash": "407cc89f4bb0e409146c863dee51b0ae", + "hash": "c1a76530df6b9daa16b8033d61b76503", "packages": [ { "name": "symfony/config", @@ -273,6 +273,64 @@ "homepage": "http://symfony.com" }, { + "name": "symfony/routing", + "version": "v2.1.3", + "target-dir": "Symfony/Component/Routing", + "source": { + "type": "git", + "url": "https://github.com/symfony/Routing", + "reference": "v2.1.3" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/Routing/zipball/v2.1.3", + "reference": "v2.1.3", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "symfony/config": "2.1.*", + "symfony/yaml": "2.1.*", + "symfony/http-kernel": "2.1.*", + "doctrine/common": ">=2.2,<2.4-dev" + }, + "suggest": { + "symfony/config": "2.1.*", + "symfony/yaml": "2.1.*", + "doctrine/common": ">=2.2,<2.4-dev" + }, + "time": "2012-10-26 02:26:42", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\Routing": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Routing Component", + "homepage": "http://symfony.com" + }, + { "name": "symfony/yaml", "version": "v2.1.3", "target-dir": "Symfony/Component/Yaml", @@ -323,29 +381,29 @@ "packages-dev": [ { "name": "fabpot/goutte", - "version": "dev-master", + "version": "v0.1.0", "source": { "type": "git", "url": "https://github.com/fabpot/Goutte", - "reference": "f2940f9c7c1f409159f5e9f512e575946c5cff48" + "reference": "v0.1.0" }, "dist": { "type": "zip", - "url": "https://github.com/fabpot/Goutte/zipball/f2940f9c7c1f409159f5e9f512e575946c5cff48", - "reference": "f2940f9c7c1f409159f5e9f512e575946c5cff48", + "url": "https://github.com/fabpot/Goutte/archive/v0.1.0.zip", + "reference": "v0.1.0", "shasum": "" }, "require": { "php": ">=5.3.0", + "ext-curl": "*", "symfony/browser-kit": "2.1.*", "symfony/css-selector": "2.1.*", "symfony/dom-crawler": "2.1.*", "symfony/finder": "2.1.*", "symfony/process": "2.1.*", - "ext-curl": "*", - "guzzle/http": "2.8.*" + "guzzle/guzzle": "3.0.*" }, - "time": "1351086217", + "time": "2012-12-02 13:44:35", "type": "application", "extra": { "branch-alias": { @@ -374,126 +432,90 @@ ] }, { - "name": "guzzle/common", - "version": "v2.8.8", - "target-dir": "Guzzle/Common", + "name": "guzzle/guzzle", + "version": "v3.0.5", "source": { "type": "git", - "url": "git://github.com/guzzle/common.git", - "reference": "v2.8.8" + "url": "https://github.com/guzzle/guzzle", + "reference": "v3.0.5" }, "dist": { "type": "zip", - "url": "https://github.com/guzzle/common/zipball/v2.8.8", - "reference": "v2.8.8", + "url": "https://github.com/guzzle/guzzle/archive/v3.0.5.zip", + "reference": "v3.0.5", "shasum": "" }, "require": { "php": ">=5.3.2", + "ext-curl": "*", "symfony/event-dispatcher": "2.1.*" }, - "time": "2012-10-15 17:42:47", - "type": "library", - "installation-source": "dist", - "autoload": { - "psr-0": { - "Guzzle\\Common": "" - } - }, - "license": [ - "MIT" - ], - "description": "Common libraries used by Guzzle", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "log", - "event", - "cache", - "validation", - "Socket", - "common", - "batch", - "inflection" - ] - }, - { - "name": "guzzle/http", - "version": "v2.8.8", - "target-dir": "Guzzle/Http", - "source": { - "type": "git", - "url": "git://github.com/guzzle/http.git", - "reference": "v2.8.8" - }, - "dist": { - "type": "zip", - "url": "https://github.com/guzzle/http/zipball/v2.8.8", - "reference": "v2.8.8", - "shasum": "" - }, - "require": { - "php": ">=5.3.2", + "replace": { + "guzzle/batch": "self.version", + "guzzle/cache": "self.version", "guzzle/common": "self.version", - "guzzle/parser": "self.version" + "guzzle/http": "self.version", + "guzzle/inflection": "self.version", + "guzzle/iterator": "self.version", + "guzzle/log": "self.version", + "guzzle/parser": "self.version", + "guzzle/plugin": "self.version", + "guzzle/plugin-async": "self.version", + "guzzle/plugin-backoff": "self.version", + "guzzle/plugin-cache": "self.version", + "guzzle/plugin-cookie": "self.version", + "guzzle/plugin-curlauth": "self.version", + "guzzle/plugin-history": "self.version", + "guzzle/plugin-log": "self.version", + "guzzle/plugin-md5": "self.version", + "guzzle/plugin-mock": "self.version", + "guzzle/plugin-oauth": "self.version", + "guzzle/service": "self.version", + "guzzle/stream": "self.version" }, - "time": "2012-10-15 17:42:47", + "require-dev": { + "doctrine/common": "*", + "symfony/class-loader": "*", + "monolog/monolog": "1.*", + "zendframework/zend-cache": "2.0.*", + "zendframework/zend-log": "2.0.*", + "zend/zend-log1": "1.12", + "zend/zend-cache1": "1.12", + "phpunit/phpunit": "3.7.*" + }, + "time": "2012-11-19 00:15:33", "type": "library", "installation-source": "dist", "autoload": { "psr-0": { - "Guzzle\\Http": "" + "Guzzle\\Tests": "tests/", + "Guzzle": "src/" } }, "license": [ "MIT" ], - "description": "HTTP libraries used by Guzzle", + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Guzzle Community", + "homepage": "https://github.com/guzzle/guzzle/contributors" + } + ], + "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients", "homepage": "http://guzzlephp.org/", "keywords": [ + "framework", "curl", "http", + "rest", "http client", "client", - "Guzzle" - ] - }, - { - "name": "guzzle/parser", - "version": "v2.8.8", - "target-dir": "Guzzle/Parser", - "source": { - "type": "git", - "url": "git://github.com/guzzle/parser.git", - "reference": "v2.8.8" - }, - "dist": { - "type": "zip", - "url": "https://github.com/guzzle/parser/zipball/v2.8.8", - "reference": "v2.8.8", - "shasum": "" - }, - "require": { - "php": ">=5.3.2" - }, - "time": "2012-09-20 13:28:06", - "type": "library", - "installation-source": "dist", - "autoload": { - "psr-0": { - "Guzzle\\Parser": "" - } - }, - "license": [ - "MIT" - ], - "description": "Interchangeable parsers used by Guzzle", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "http", - "url", - "message", - "cookie", - "URI Template" + "web service" ] }, { @@ -750,7 +772,7 @@ ], "minimum-stability": "beta", - "stability-flags": { - "fabpot/goutte": 20 - } + "stability-flags": [ + + ] } diff --git a/phpBB/config/routing.yml b/phpBB/config/routing.yml new file mode 100644 index 0000000000..d8e890d063 --- /dev/null +++ b/phpBB/config/routing.yml @@ -0,0 +1,9 @@ +# Structure: +# +# foo_controller: +# pattern: /foo +# defaults: { _controller: foo_sevice:method } +# +# The above will be accessed via app.php?controller=foo and it will +# instantiate the "foo_service" service and call the "method" method. +# diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 991d7381e2..a09113f056 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -44,6 +44,30 @@ services: - @cache.driver - %tables.config% + controller.helper: + class: phpbb_controller_helper + arguments: + - @template + - @user + - %core.root_path% + - .%core.php_ext% + + controller.resolver: + class: phpbb_controller_resolver + arguments: + - @user + - @service_container + - @ext.finder + + controller.route_collection: + class: phpbb_controller_route_collection + arguments: + - @ext.finder + - @controller.provider + + controller.provider: + class: phpbb_controller_provider + cron.task_collection: class: phpbb_di_service_collection arguments: @@ -93,6 +117,22 @@ services: - .%core.php_ext% - @cache.driver + ext.finder: + class: phpbb_extension_finder + arguments: + - @ext.manager + - %core.root_path% + - @cache.driver + - .%core.php_ext% + - _ext_finder + + http_kernel: + class: Symfony\Component\HttpKernel\HttpKernel + arguments: + - @dispatcher + - @controller.resolver + + groupposition.legend: class: phpbb_groupposition_legend arguments: @@ -106,6 +146,28 @@ services: - @user - @cache.driver + kernel_request_subscriber: + class: phpbb_event_kernel_request_subscriber + arguments: + - @ext.finder + - %core.root_path% + - .%core.php_ext% + tags: + - { name: kernel.event_subscriber } + + kernel_exception_subscriber: + class: phpbb_event_kernel_exception_subscriber + arguments: + - @template + - @user + tags: + - { name: kernel.event_subscriber } + + kernel_terminate_subscriber: + class: phpbb_event_kernel_terminate_subscriber + tags: + - { name: kernel.event_subscriber } + request: class: phpbb_request diff --git a/phpBB/develop/generate_utf_casefold.php b/phpBB/develop/generate_utf_casefold.php index 5b99f3e55e..ad511a6153 100644 --- a/phpBB/develop/generate_utf_casefold.php +++ b/phpBB/develop/generate_utf_casefold.php @@ -111,7 +111,7 @@ function my_var_export($var) * Download a file to the develop/ dir * * @param string $url URL of the file to download -* @return void +* @return null */ function download($url) { diff --git a/phpBB/develop/generate_utf_confusables.php b/phpBB/develop/generate_utf_confusables.php index 027d75b661..763d8ee875 100644 --- a/phpBB/develop/generate_utf_confusables.php +++ b/phpBB/develop/generate_utf_confusables.php @@ -199,7 +199,7 @@ function my_var_export($var) * Download a file to the develop/ dir * * @param string $url URL of the file to download -* @return void +* @return null */ function download($url) { diff --git a/phpBB/develop/generate_utf_tables.php b/phpBB/develop/generate_utf_tables.php index 71a5bea851..e5d907d6a5 100644 --- a/phpBB/develop/generate_utf_tables.php +++ b/phpBB/develop/generate_utf_tables.php @@ -481,7 +481,7 @@ function my_var_export($var) * Download a file to the develop/ dir * * @param string $url URL of the file to download -* @return void +* @return null */ function download($url) { diff --git a/phpBB/develop/utf_normalizer_test.php b/phpBB/develop/utf_normalizer_test.php index 186e10fea2..af8556507f 100644 --- a/phpBB/develop/utf_normalizer_test.php +++ b/phpBB/develop/utf_normalizer_test.php @@ -222,7 +222,7 @@ die("\n\nALL TESTS PASSED SUCCESSFULLY\n"); * Download a file to the develop/ dir * * @param string $url URL of the file to download -* @return void +* @return null */ function download($url) { diff --git a/phpBB/docs/INSTALL.html b/phpBB/docs/INSTALL.html index 07f0cbc8c2..58aeb904c7 100644 --- a/phpBB/docs/INSTALL.html +++ b/phpBB/docs/INSTALL.html @@ -132,7 +132,7 @@ <li>A SQL database system, <strong>one of</strong>: <ul> <li>MySQL 3.23 or above (MySQLi supported)</li> - <li>PostgreSQL 7.3+</li> + <li>PostgreSQL 8.3+</li> <li>SQLite 2.8.2+ (SQLite 3 is not supported)</li> <li>Firebird 2.1+</li> <li>MS SQL Server 2000 or above (directly or via ODBC or the native adapter)</li> diff --git a/phpBB/docs/README.html b/phpBB/docs/README.html index 0e0d3b14fd..164c4a2f55 100644 --- a/phpBB/docs/README.html +++ b/phpBB/docs/README.html @@ -324,11 +324,7 @@ <p>Please remember that running any application on a developmental version of PHP can lead to strange/unexpected results which may appear to be bugs in the application (which may not be true). Therefore we recommend you upgrade to the newest stable version of PHP before running phpBB3. If you are running a developmental version of PHP please check any bugs you find on a system running a stable release before submitting.</p> -<<<<<<< HEAD - <p>This board has been developed and tested under Linux and Windows (amongst others) running Apache using MySQL 3.23, 4.x, 5.x, MSSQL Server 2000, PostgreSQL 8.x, Oracle 8, SQLite and Firebird. Versions of PHP used range from 5.3.x to 5.4.x without problem.</p> -======= - <p>This board has been developed and tested under Linux and Windows (amongst others) running Apache using MySQL 3.23, 4.x, 5.x, MSSQL Server 2000, PostgreSQL 7.x, Oracle 8, SQLite 2 and Firebird. Versions of PHP used range from 4.3.3 to 5.4.x without problem. </p> ->>>>>>> develop-olympus + <p>This board has been developed and tested under Linux and Windows (amongst others) running Apache using MySQL 3.23, 4.x, 5.x, MSSQL Server 2000, PostgreSQL 8.x, Oracle 8, SQLite 2 and Firebird. Versions of PHP used range from 5.3.x to 5.4.x without problem.</p> <a name="phpsec"></a><h3>7.i. Notice on PHP security issues</h3> diff --git a/phpBB/docs/auth_api.html b/phpBB/docs/auth_api.html index 2302140030..249ceebfbc 100644 --- a/phpBB/docs/auth_api.html +++ b/phpBB/docs/auth_api.html @@ -193,7 +193,7 @@ $user_id = 2; $auth->acl_clear_prefetch($user_id); </pre></div> - <p>This method returns void.</p> + <p>This method returns null.</p> <a name="acl_get_list"></a><h3>2.viii. acl_get_list</h3> diff --git a/phpBB/docs/coding-guidelines.html b/phpBB/docs/coding-guidelines.html index 0e3a97c004..eb569d12d5 100644 --- a/phpBB/docs/coding-guidelines.html +++ b/phpBB/docs/coding-guidelines.html @@ -740,7 +740,7 @@ static private function f() <a name="sql"></a><h3>2.iii. SQL/SQL Layout</h3> <h4>Common SQL Guidelines: </h4> - <p>All SQL should be cross-DB compatible, if DB specific SQL is used alternatives must be provided which work on all supported DB's (MySQL3/4/5, MSSQL (7.0 and 2000), PostgreSQL (7.0+), Firebird, SQLite, Oracle8, ODBC (generalised if possible)).</p> + <p>All SQL should be cross-DB compatible, if DB specific SQL is used alternatives must be provided which work on all supported DB's (MySQL3/4/5, MSSQL (7.0 and 2000), PostgreSQL (8.3+), Firebird, SQLite, Oracle8, ODBC (generalised if possible)).</p> <p>All SQL commands should utilise the DataBase Abstraction Layer (DBAL)</p> <h4>SQL code layout:</h4> diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 79f53245b9..73b9e0a9f2 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -42,8 +42,6 @@ if (isset($_GET['avatar'])) } require($phpbb_root_path . 'includes/class_loader.' . $phpEx); - require($phpbb_root_path . 'includes/di/processor/interface.' . $phpEx); - require($phpbb_root_path . 'includes/di/processor/config.' . $phpEx); require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); @@ -66,6 +64,7 @@ if (isset($_GET['avatar'])) ), array( new phpbb_di_pass_collection_pass(), + new phpbb_di_pass_kernel_pass(), ), $phpbb_root_path, $phpEx diff --git a/phpBB/includes/cache/driver/apc.php b/phpBB/includes/cache/driver/apc.php index dc0144fac3..0516b669c8 100644 --- a/phpBB/includes/cache/driver/apc.php +++ b/phpBB/includes/cache/driver/apc.php @@ -26,7 +26,7 @@ class phpbb_cache_driver_apc extends phpbb_cache_driver_memory /** * Purge cache data * - * @return void + * @return null */ function purge() { diff --git a/phpBB/includes/cache/driver/eaccelerator.php b/phpBB/includes/cache/driver/eaccelerator.php index 7939f043c9..257b90c76e 100644 --- a/phpBB/includes/cache/driver/eaccelerator.php +++ b/phpBB/includes/cache/driver/eaccelerator.php @@ -30,7 +30,7 @@ class phpbb_cache_driver_eaccelerator extends phpbb_cache_driver_memory /** * Purge cache data * - * @return void + * @return null */ function purge() { @@ -47,7 +47,7 @@ class phpbb_cache_driver_eaccelerator extends phpbb_cache_driver_memory /** * Perform cache garbage collection * - * @return void + * @return null */ function tidy() { diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php index 32bdb1918a..691abe0438 100644 --- a/phpBB/includes/cache/driver/file.php +++ b/phpBB/includes/cache/driver/file.php @@ -215,6 +215,7 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base while (($entry = readdir($dir)) !== false) { if (strpos($entry, 'container_') !== 0 && + strpos($entry, 'url_matcher') !== 0 && strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && @@ -387,10 +388,10 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base if ($this->_write('sql_' . md5($query), $this->sql_rowset[$query_id], $ttl + time(), $query)) { - $query_result = $query_id; + return $query_id; } - return $query_id; + return $query_result; } /** @@ -652,10 +653,11 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base $file = "{$this->cache_dir}$filename.$phpEx"; + $lock = new phpbb_lock_flock($file); + $lock->acquire(); + if ($handle = @fopen($file, 'wb')) { - @flock($handle, LOCK_EX); - // File header fwrite($handle, '<' . '?php exit; ?' . '>'); @@ -696,7 +698,6 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base fwrite($handle, $data); } - @flock($handle, LOCK_UN); fclose($handle); if (!function_exists('phpbb_chmod')) @@ -707,10 +708,16 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base phpbb_chmod($file, CHMOD_READ | CHMOD_WRITE); - return true; + $return_value = true; + } + else + { + $return_value = false; } - return false; + $lock->release(); + + return $return_value; } /** diff --git a/phpBB/includes/cache/driver/interface.php b/phpBB/includes/cache/driver/interface.php index 847ba97262..d403bbcd71 100644 --- a/phpBB/includes/cache/driver/interface.php +++ b/phpBB/includes/cache/driver/interface.php @@ -63,42 +63,81 @@ interface phpbb_cache_driver_interface public function destroy($var_name, $table = ''); /** - * Check if a given cache entry exist + * Check if a given cache entry exists */ public function _exists($var_name); /** - * Load cached sql query + * Load result of an SQL query from cache. + * + * @param string $query SQL query + * + * @return int|bool Query ID (integer) if cache contains a rowset + * for the specified query. + * False otherwise. */ public function sql_load($query); /** - * Save sql query + * Save result of an SQL query in cache. + * + * In persistent cache stores, this function stores the query + * result to persistent storage. In other words, there is no need + * to call save() afterwards. + * + * @param string $query SQL query, should be used for generating storage key + * @param mixed $query_result The result from dbal::sql_query, to be passed to + * dbal::sql_fetchrow to get all rows and store them + * in cache. + * @param int $ttl Time to live, after this timeout the query should + * expire from the cache. + * @return int|mixed If storing in cache succeeded, an integer $query_id + * representing the query should be returned. Otherwise + * the original $query_result should be returned. */ public function sql_save($query, $query_result, $ttl); /** - * Ceck if a given sql query exist in cache + * Check if result for a given SQL query exists in cache. + * + * @param int $query_id + * @return bool */ public function sql_exists($query_id); /** * Fetch row from cache (database) + * + * @param int $query_id + * @return array|bool The query result if found in the cache, otherwise + * false. */ public function sql_fetchrow($query_id); /** * Fetch a field from the current row of a cached database result (database) + * + * @param int $query_id + * @param $field The name of the column. + * @return string|bool The field of the query result if found in the cache, + * otherwise false. */ public function sql_fetchfield($query_id, $field); /** * Seek a specific row in an a cached database result (database) + * + * @param int $rownum Row to seek to. + * @param int $query_id + * @return bool */ public function sql_rowseek($rownum, $query_id); /** * Free memory used for a cached database result (database) + * + * @param int $query_id + * @return bool */ public function sql_freeresult($query_id); } diff --git a/phpBB/includes/cache/driver/memcache.php b/phpBB/includes/cache/driver/memcache.php index 9fe70f8b44..3fd16b23b0 100644 --- a/phpBB/includes/cache/driver/memcache.php +++ b/phpBB/includes/cache/driver/memcache.php @@ -64,7 +64,7 @@ class phpbb_cache_driver_memcache extends phpbb_cache_driver_memory /** * Unload the cache resources * - * @return void + * @return null */ function unload() { @@ -76,7 +76,7 @@ class phpbb_cache_driver_memcache extends phpbb_cache_driver_memory /** * Purge cache data * - * @return void + * @return null */ function purge() { diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php index 1ea9a3e9e7..c39f9f7850 100644 --- a/phpBB/includes/cache/driver/memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -163,6 +163,7 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base while (($entry = readdir($dir)) !== false) { if (strpos($entry, 'container_') !== 0 && + strpos($entry, 'url_matcher') !== 0 && strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && @@ -298,7 +299,7 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base if (!preg_match('/FROM \\(?(`?\\w+`?(?: \\w+)?(?:, ?`?\\w+`?(?: \\w+)?)*)\\)?/', $query, $regs)) { // Bail out if the match fails. - return; + return $query_result; } $tables = array_map('trim', explode(',', $regs[1])); @@ -338,8 +339,6 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base $this->_write('sql_' . $hash, $this->sql_rowset[$query_id], $ttl); - $query_result = $query_id; - return $query_id; } diff --git a/phpBB/includes/cache/driver/null.php b/phpBB/includes/cache/driver/null.php index df2c6c026f..687604d14f 100644 --- a/phpBB/includes/cache/driver/null.php +++ b/phpBB/includes/cache/driver/null.php @@ -109,6 +109,7 @@ class phpbb_cache_driver_null extends phpbb_cache_driver_base */ function sql_save($query, $query_result, $ttl) { + return $query_result; } /** diff --git a/phpBB/includes/cache/driver/redis.php b/phpBB/includes/cache/driver/redis.php index a768885962..960735b673 100644 --- a/phpBB/includes/cache/driver/redis.php +++ b/phpBB/includes/cache/driver/redis.php @@ -39,13 +39,39 @@ class phpbb_cache_driver_redis extends phpbb_cache_driver_memory var $redis; + /** + * Creates a redis cache driver. + * + * The following global constants affect operation: + * + * PHPBB_ACM_REDIS_HOST + * PHPBB_ACM_REDIS_PORT + * PHPBB_ACM_REDIS_PASSWORD + * PHPBB_ACM_REDIS_DB + * + * There are no publicly documented constructor parameters. + */ function __construct() { // Call the parent constructor parent::__construct(); $this->redis = new Redis(); - $this->redis->connect(PHPBB_ACM_REDIS_HOST, PHPBB_ACM_REDIS_PORT); + + $args = func_get_args(); + if (!empty($args)) + { + $ok = call_user_func_array(array($this->redis, 'connect'), $args); + } + else + { + $ok = $this->redis->connect(PHPBB_ACM_REDIS_HOST, PHPBB_ACM_REDIS_PORT); + } + + if (!$ok) + { + trigger_error('Could not connect to redis server'); + } if (defined('PHPBB_ACM_REDIS_PASSWORD')) { @@ -74,7 +100,7 @@ class phpbb_cache_driver_redis extends phpbb_cache_driver_memory /** * Unload the cache resources * - * @return void + * @return null */ function unload() { @@ -86,7 +112,7 @@ class phpbb_cache_driver_redis extends phpbb_cache_driver_memory /** * Purge cache data * - * @return void + * @return null */ function purge() { diff --git a/phpBB/includes/cache/driver/wincache.php b/phpBB/includes/cache/driver/wincache.php index fa9eb95f88..58f3b4a581 100644 --- a/phpBB/includes/cache/driver/wincache.php +++ b/phpBB/includes/cache/driver/wincache.php @@ -26,7 +26,7 @@ class phpbb_cache_driver_wincache extends phpbb_cache_driver_memory /** * Purge cache data * - * @return void + * @return null */ function purge() { diff --git a/phpBB/includes/cache/driver/xcache.php b/phpBB/includes/cache/driver/xcache.php index 0b768bdb3e..06c5fafd97 100644 --- a/phpBB/includes/cache/driver/xcache.php +++ b/phpBB/includes/cache/driver/xcache.php @@ -41,7 +41,7 @@ class phpbb_cache_driver_xcache extends phpbb_cache_driver_memory /** * Purge cache data * - * @return void + * @return null */ function purge() { diff --git a/phpBB/includes/config/config.php b/phpBB/includes/config/config.php index 12a4a418b2..4b533dd55c 100644 --- a/phpBB/includes/config/config.php +++ b/phpBB/includes/config/config.php @@ -109,7 +109,7 @@ class phpbb_config implements ArrayAccess, IteratorAggregate, Countable * @param String $key The configuration option's name * @param bool $use_cache Whether this variable should be cached or if it * changes too frequently to be efficiently cached - * @return void + * @return null */ public function delete($key, $use_cache = true) { diff --git a/phpBB/includes/config/db.php b/phpBB/includes/config/db.php index 993a764a7f..45f9f1cb21 100644 --- a/phpBB/includes/config/db.php +++ b/phpBB/includes/config/db.php @@ -96,7 +96,7 @@ class phpbb_config_db extends phpbb_config * @param String $key The configuration option's name * @param bool $use_cache Whether this variable should be cached or if it * changes too frequently to be efficiently cached - * @return void + * @return null */ public function delete($key, $use_cache = true) { diff --git a/phpBB/includes/controller/exception.php b/phpBB/includes/controller/exception.php new file mode 100644 index 0000000000..faa8b6b584 --- /dev/null +++ b/phpBB/includes/controller/exception.php @@ -0,0 +1,24 @@ +<?php +/** +* +* @package controller +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Controller exception class +* @package phpBB3 +*/ +class phpbb_controller_exception extends RuntimeException +{ +} diff --git a/phpBB/includes/controller/helper.php b/phpBB/includes/controller/helper.php new file mode 100644 index 0000000000..6cacc8fefa --- /dev/null +++ b/phpBB/includes/controller/helper.php @@ -0,0 +1,117 @@ +<?php +/** +* +* @package controller +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +use Symfony\Component\HttpFoundation\Response; + +/** +* Controller helper class, contains methods that do things for controllers +* @package phpBB3 +*/ +class phpbb_controller_helper +{ + /** + * Template object + * @var phpbb_template + */ + protected $template; + + /** + * User object + * @var phpbb_user + */ + protected $user; + + /** + * phpBB root path + * @var string + */ + protected $phpbb_root_path; + + /** + * PHP extension + * @var string + */ + protected $php_ext; + + /** + * Constructor + * + * @param phpbb_template $template Template object + * @param phpbb_user $user User object + * @param string $phpbb_root_path phpBB root path + * @param string $php_ext PHP extension + */ + public function __construct(phpbb_template $template, phpbb_user $user, $phpbb_root_path, $php_ext) + { + $this->template = $template; + $this->user = $user; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + + /** + * Automate setting up the page and creating the response object. + * + * @param string $handle The template handle to render + * @param string $page_title The title of the page to output + * @param int $status_code The status code to be sent to the page header + * @return Response object containing rendered page + */ + public function render($template_file, $page_title = '', $status_code = 200) + { + page_header($page_title); + + $this->template->set_filenames(array( + 'body' => $template_file, + )); + + page_footer(true, false, false); + + return new Response($this->template->assign_display('body'), $status_code); + } + + /** + * Easily generate a URL + * + * @param array $url_parts Each array element is a 'folder' + * i.e. array('my', 'ext') maps to ./app.php/my/ext + * @param mixed $query The Query string, passed directly into the second + * argument of append_sid() + * @return string A URL that has already been run through append_sid() + */ + public function url(array $url_parts, $query = '') + { + return append_sid($this->phpbb_root_path . implode('/', $url_parts), $query); + } + + /** + * Output an error, effectively the same thing as trigger_error + * + * @param string $message The error message + * @param string $code The error code (e.g. 404, 500, 503, etc.) + * @return Response A Reponse instance + */ + public function error($message, $code = 500) + { + $this->template->assign_vars(array( + 'MESSAGE_TEXT' => $message, + 'MESSAGE_TITLE' => $this->user->lang('INFORMATION'), + )); + + return $this->render('message_body.html', $this->user->lang('INFORMATION'), $code); + } +} diff --git a/phpBB/includes/controller/provider.php b/phpBB/includes/controller/provider.php new file mode 100644 index 0000000000..b2a5b9f6b2 --- /dev/null +++ b/phpBB/includes/controller/provider.php @@ -0,0 +1,82 @@ +<?php +/** +* +* @package controller +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +use Symfony\Component\Routing\RouteCollection; +use Symfony\Component\Routing\Loader\YamlFileLoader; +use Symfony\Component\Config\FileLocator; + +/** +* Controller interface +* @package phpBB3 +*/ +class phpbb_controller_provider +{ + /** + * YAML file(s) containing route information + * @var array + */ + protected $routing_paths; + + /** + * Construct method + * + * @param array() $routing_paths Array of strings containing paths + * to YAML files holding route information + */ + public function __construct($routing_paths = array()) + { + $this->routing_paths = $routing_paths; + } + + /** + * Locate paths containing routing files + * This sets an internal property but does not return the paths. + * + * @return The current instance of this object for method chaining + */ + public function import_paths_from_finder(phpbb_extension_finder $finder) + { + // We hardcode the path to the core config directory + // because the finder cannot find it + $this->routing_paths = array_merge(array('config'), array_map('dirname', array_keys($finder + ->directory('config') + ->prefix('routing') + ->suffix('yml') + ->find() + ))); + + return $this; + } + + /** + * Get a list of controllers and return it + * + * @param string $base_path Base path to prepend to file paths + * @return array Array of controllers and their route information + */ + public function find($base_path = '') + { + $routes = new RouteCollection; + foreach ($this->routing_paths as $path) + { + $loader = new YamlFileLoader(new FileLocator($base_path . $path)); + $routes->addCollection($loader->load('routing.yml')); + } + + return $routes; + } +} diff --git a/phpBB/includes/controller/resolver.php b/phpBB/includes/controller/resolver.php new file mode 100644 index 0000000000..ee469aa9c8 --- /dev/null +++ b/phpBB/includes/controller/resolver.php @@ -0,0 +1,128 @@ +<?php +/** +* +* @package controller +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\Request; + +/** +* Controller manager class +* @package phpBB3 +*/ +class phpbb_controller_resolver implements ControllerResolverInterface +{ + /** + * User object + * @var phpbb_user + */ + protected $user; + + /** + * ContainerInterface object + * @var ContainerInterface + */ + protected $container; + + /** + * Construct method + * + * @param phpbb_user $user User Object + * @param ContainerInterface $container ContainerInterface object + */ + public function __construct(phpbb_user $user, ContainerInterface $container) + { + $this->user = $user; + $this->container = $container; + } + + /** + * Load a controller callable + * + * @param Symfony\Component\HttpFoundation\Request $request Symfony Request object + * @return bool|Callable Callable or false + * @throws phpbb_controller_exception + */ + public function getController(Request $request) + { + $controller = $request->attributes->get('_controller'); + + if (!$controller) + { + throw new phpbb_controller_exception($this->user->lang['CONTROLLER_NOT_SPECIFIED']); + } + + // Require a method name along with the service name + if (stripos($controller, ':') === false) + { + throw new phpbb_controller_exception($this->user->lang['CONTROLLER_METHOD_NOT_SPECIFIED']); + } + + list($service, $method) = explode(':', $controller); + + if (!$this->container->has($service)) + { + throw new phpbb_controller_exception($this->user->lang('CONTROLLER_SERVICE_UNDEFINED', $service)); + } + + $controller_object = $this->container->get($service); + + return array($controller_object, $method); + } + + /** + * Dependencies should be specified in the service definition and can be + * then accessed in __construct(). Arguments are sent through the URL path + * and should match the parameters of the method you are using as your + * controller. + * + * @param Symfony\Component\HttpFoundation\Request $request Symfony Request object + * @param mixed $controller A callable (controller class, method) + * @return bool False + * @throws phpbb_controller_exception + */ + public function getArguments(Request $request, $controller) + { + // At this point, $controller contains the object and method name + list($object, $method) = $controller; + $mirror = new ReflectionMethod($object, $method); + + $arguments = array(); + $parameters = $mirror->getParameters(); + $attributes = $request->attributes->all(); + foreach ($parameters as $param) + { + if (array_key_exists($param->name, $attributes)) + { + $arguments[] = $attributes[$param->name]; + } + else if ($param->getClass() && $param->getClass()->isInstance($request)) + { + $arguments[] = $request; + } + else if ($param->isDefaultValueAvailable()) + { + $arguments[] = $param->getDefaultValue(); + } + else + { + throw new phpbb_controller_exception($this->user->lang('CONTROLLER_ARGUMENT_VALUE_MISSING', $param->getPosition() + 1, get_class($object) . ':' . $method, $param->name)); + } + } + + return $arguments; + } +} diff --git a/phpBB/includes/cron/manager.php b/phpBB/includes/cron/manager.php index ccaa4f3764..84c9650830 100644 --- a/phpBB/includes/cron/manager.php +++ b/phpBB/includes/cron/manager.php @@ -54,7 +54,7 @@ class phpbb_cron_manager * * @param array|Traversable $tasks Array of instances of phpbb_cron_task * - * @return void + * @return null */ public function load_tasks($tasks) { diff --git a/phpBB/includes/cron/task/core/prune_all_forums.php b/phpBB/includes/cron/task/core/prune_all_forums.php index 252e16e57d..ee0b5f7626 100644 --- a/phpBB/includes/cron/task/core/prune_all_forums.php +++ b/phpBB/includes/cron/task/core/prune_all_forums.php @@ -50,7 +50,7 @@ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/core/prune_forum.php b/phpBB/includes/cron/task/core/prune_forum.php index 41d60af921..fa7a761d88 100644 --- a/phpBB/includes/cron/task/core/prune_forum.php +++ b/phpBB/includes/cron/task/core/prune_forum.php @@ -70,7 +70,7 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p /** * Runs this cron task. * - * @return void + * @return null */ public function run() { @@ -138,7 +138,7 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p * * @param phpbb_request_interface $request Request object. * - * @return void + * @return null */ public function parse_parameters(phpbb_request_interface $request) { diff --git a/phpBB/includes/cron/task/core/queue.php b/phpBB/includes/cron/task/core/queue.php index c765660906..732f9c6bea 100644 --- a/phpBB/includes/cron/task/core/queue.php +++ b/phpBB/includes/cron/task/core/queue.php @@ -43,7 +43,7 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/core/tidy_cache.php b/phpBB/includes/cron/task/core/tidy_cache.php index 6017eea561..16a45dae7c 100644 --- a/phpBB/includes/cron/task/core/tidy_cache.php +++ b/phpBB/includes/cron/task/core/tidy_cache.php @@ -40,7 +40,7 @@ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/core/tidy_database.php b/phpBB/includes/cron/task/core/tidy_database.php index 1d256f964f..b882e7b500 100644 --- a/phpBB/includes/cron/task/core/tidy_database.php +++ b/phpBB/includes/cron/task/core/tidy_database.php @@ -43,7 +43,7 @@ class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/core/tidy_search.php b/phpBB/includes/cron/task/core/tidy_search.php index 2e5f3d79d5..fdbe31346e 100644 --- a/phpBB/includes/cron/task/core/tidy_search.php +++ b/phpBB/includes/cron/task/core/tidy_search.php @@ -54,7 +54,7 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/core/tidy_sessions.php b/phpBB/includes/cron/task/core/tidy_sessions.php index 13531aa30b..95f55235c9 100644 --- a/phpBB/includes/cron/task/core/tidy_sessions.php +++ b/phpBB/includes/cron/task/core/tidy_sessions.php @@ -40,7 +40,7 @@ class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/core/tidy_warnings.php b/phpBB/includes/cron/task/core/tidy_warnings.php index 8dd0674fe5..2a7798e56e 100644 --- a/phpBB/includes/cron/task/core/tidy_warnings.php +++ b/phpBB/includes/cron/task/core/tidy_warnings.php @@ -45,7 +45,7 @@ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/parametrized.php b/phpBB/includes/cron/task/parametrized.php index 0714b2e701..5f0e46eafc 100644 --- a/phpBB/includes/cron/task/parametrized.php +++ b/phpBB/includes/cron/task/parametrized.php @@ -46,7 +46,7 @@ interface phpbb_cron_task_parametrized extends phpbb_cron_task * * @param phpbb_request_interface $request Request object. * - * @return void + * @return null */ public function parse_parameters(phpbb_request_interface $request); } diff --git a/phpBB/includes/cron/task/task.php b/phpBB/includes/cron/task/task.php index 7b08fed413..2d585df96d 100644 --- a/phpBB/includes/cron/task/task.php +++ b/phpBB/includes/cron/task/task.php @@ -31,7 +31,7 @@ interface phpbb_cron_task /** * Runs this cron task. * - * @return void + * @return null */ public function run(); diff --git a/phpBB/includes/di/extension/ext.php b/phpBB/includes/di/extension/ext.php index e76c543ee1..7d9b433751 100644 --- a/phpBB/includes/di/extension/ext.php +++ b/phpBB/includes/di/extension/ext.php @@ -49,7 +49,7 @@ class phpbb_di_extension_ext extends Extension { if (file_exists($path . '/config/services.yml')) { - $loader = new YamlFileLoader($container, new FileLocator(phpbb_real_path($path . '/config'))); + $loader = new YamlFileLoader($container, new FileLocator(phpbb_realpath($path . '/config'))); $loader->load('services.yml'); } } diff --git a/phpBB/includes/di/pass/kernel_pass.php b/phpBB/includes/di/pass/kernel_pass.php new file mode 100644 index 0000000000..a701ebcfa6 --- /dev/null +++ b/phpBB/includes/di/pass/kernel_pass.php @@ -0,0 +1,68 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; + +class phpbb_di_pass_kernel_pass implements CompilerPassInterface +{ + /** + * Modify the container before it is passed to the rest of the code + * + * @param ContainerBuilder $container ContainerBuilder object + * @return null + */ + public function process(ContainerBuilder $container) + { + $definition = $container->getDefinition('dispatcher'); + + foreach ($container->findTaggedServiceIds('kernel.event_listener') as $id => $events) + { + foreach ($events as $event) + { + $priority = isset($event['priority']) ? $event['priority'] : 0; + + if (!isset($event['event'])) + { + throw new InvalidArgumentException(sprintf('Service "%1$s" must define the "event" attribute on "kernel.event_listener" tags.', $id)); + } + + if (!isset($event['method'])) + { + throw new InvalidArgumentException(sprintf('Service "%1$s" must define the "method" attribute on "kernel.event_listener" tags.', $id)); + } + + $definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority)); + } + } + + foreach ($container->findTaggedServiceIds('kernel.event_subscriber') as $id => $attributes) + { + // We must assume that the class value has been correctly filled, even if the service is created by a factory + $class = $container->getDefinition($id)->getClass(); + + $refClass = new ReflectionClass($class); + $interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface'; + if (!$refClass->implementsInterface($interface)) + { + throw new InvalidArgumentException(sprintf('Service "%1$s" must implement interface "%2$s".', $id, $interface)); + } + + $definition->addMethodCall('addSubscriberService', array($id, $class)); + } + } +} diff --git a/phpBB/includes/event/kernel_exception_subscriber.php b/phpBB/includes/event/kernel_exception_subscriber.php new file mode 100644 index 0000000000..f90989a74c --- /dev/null +++ b/phpBB/includes/event/kernel_exception_subscriber.php @@ -0,0 +1,85 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpKernel\KernelEvents; +use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\Exception\HttpException; +use Symfony\Component\HttpFoundation\Response; + +class phpbb_event_kernel_exception_subscriber implements EventSubscriberInterface +{ + /** + * Template object + * @var phpbb_template + */ + protected $template; + + /** + * User object + * @var phpbb_user + */ + protected $user; + + /** + * Construct method + * + * @param phpbb_template $template Template object + * @param phpbb_user $user User object + */ + public function __construct(phpbb_template $template, phpbb_user $user) + { + $this->template = $template; + $this->user = $user; + } + + /** + * This listener is run when the KernelEvents::EXCEPTION event is triggered + * + * @param GetResponseForExceptionEvent $event + * @return null + */ + public function on_kernel_exception(GetResponseForExceptionEvent $event) + { + page_header($this->user->lang('INFORMATION')); + + $exception = $event->getException(); + + $this->template->assign_vars(array( + 'MESSAGE_TITLE' => $this->user->lang('INFORMATION'), + 'MESSAGE_TEXT' => $exception->getMessage(), + )); + + $this->template->set_filenames(array( + 'body' => 'message_body.html', + )); + + page_footer(true, false, false); + + + $status_code = $exception instanceof HttpException ? $exception->getStatusCode() : 500; + $response = new Response($this->template->assign_display('body'), $status_code); + $event->setResponse($response); + } + + public static function getSubscribedEvents() + { + return array( + KernelEvents::EXCEPTION => 'on_kernel_exception', + ); + } +} diff --git a/phpBB/includes/event/kernel_request_subscriber.php b/phpBB/includes/event/kernel_request_subscriber.php new file mode 100644 index 0000000000..afb8464f80 --- /dev/null +++ b/phpBB/includes/event/kernel_request_subscriber.php @@ -0,0 +1,83 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpKernel\KernelEvents; +use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\EventListener\RouterListener; +use Symfony\Component\Routing\RequestContext; + +class phpbb_event_kernel_request_subscriber implements EventSubscriberInterface +{ + /** + * Extension finder object + * @var phpbb_extension_finder + */ + protected $finder; + + /** + * PHP extension + * @var string + */ + protected $php_ext; + + /** + * Root path + * @var string + */ + protected $root_path; + + /** + * Construct method + * + * @param phpbb_extension_finder $finder Extension finder object + * @param string $root_path Root path + * @param string $php_ext PHP extension + */ + public function __construct(phpbb_extension_finder $finder, $root_path, $php_ext) + { + $this->finder = $finder; + $this->root_path = $root_path; + $this->php_ext = $php_ext; + } + + /** + * This listener is run when the KernelEvents::REQUEST event is triggered + * + * This is responsible for setting up the routing information + * + * @param GetResponseEvent $event + * @return null + */ + public function on_kernel_request(GetResponseEvent $event) + { + $request = $event->getRequest(); + $context = new RequestContext(); + $context->fromRequest($request); + + $matcher = phpbb_get_url_matcher($this->finder, $context, $this->root_path, $this->php_ext); + $router_listener = new RouterListener($matcher, $context); + $router_listener->onKernelRequest($event); + } + + public static function getSubscribedEvents() + { + return array( + KernelEvents::REQUEST => 'on_kernel_request', + ); + } +} diff --git a/phpBB/includes/event/kernel_terminate_subscriber.php b/phpBB/includes/event/kernel_terminate_subscriber.php new file mode 100644 index 0000000000..1eaf890e42 --- /dev/null +++ b/phpBB/includes/event/kernel_terminate_subscriber.php @@ -0,0 +1,43 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpKernel\KernelEvents; +use Symfony\Component\HttpKernel\Event\PostResponseEvent; + +class phpbb_event_kernel_terminate_subscriber implements EventSubscriberInterface +{ + /** + * This listener is run when the KernelEvents::TERMINATE event is triggered + * This comes after a Response has been sent to the server; this is + * primarily cleanup stuff. + * + * @param PostResponseEvent $event + * @return null + */ + public function on_kernel_terminate(PostResponseEvent $event) + { + exit_handler(); + } + + public static function getSubscribedEvents() + { + return array( + KernelEvents::TERMINATE => 'on_kernel_terminate', + ); + } +} diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 804d89d1a2..ebe9a9918d 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -7,6 +7,8 @@ * */ +use Symfony\Component\HttpFoundation\Request; + /** * @ignore */ @@ -229,7 +231,8 @@ function phpbb_gmgetdate($time = false) /** * Return formatted string for filesizes * -* @param int $value filesize in bytes +* @param mixed $value filesize in bytes +* (non-negative number; int, float or string) * @param bool $string_only true if language string should be returned * @param array $allowed_units only allow these units (data array indexes) * @@ -241,6 +244,12 @@ function get_formatted_filesize($value, $string_only = true, $allowed_units = fa global $user; $available_units = array( + 'tb' => array( + 'min' => 1099511627776, // pow(2, 40) + 'index' => 4, + 'si_unit' => 'TB', + 'iec_unit' => 'TIB', + ), 'gb' => array( 'min' => 1073741824, // pow(2, 30) 'index' => 3, @@ -2847,12 +2856,10 @@ function meta_refresh($time, $url, $disable_cd_check = false) * * @param int $code HTTP status code * @param string $message Message for the status code -* @return void +* @return null */ function send_status_line($code, $message) { - global $request; - if (substr(strtolower(@php_sapi_name()), 0, 3) === 'cgi') { // in theory, we shouldn't need that due to php doing it. Reality offers a differing opinion, though @@ -2860,18 +2867,35 @@ function send_status_line($code, $message) } else { - if ($request->server('SERVER_PROTOCOL')) - { - $version = $request->server('SERVER_PROTOCOL'); - } - else - { - $version = 'HTTP/1.0'; - } + $version = phpbb_request_http_version(); header("$version $code $message", true, $code); } } +/** +* Returns the HTTP version used in the current request. +* +* Handles the case of being called before $request is present, +* in which case it falls back to the $_SERVER superglobal. +* +* @return string HTTP version +*/ +function phpbb_request_http_version() +{ + global $request; + + if ($request && $request->server('SERVER_PROTOCOL')) + { + return $request->server('SERVER_PROTOCOL'); + } + else if (isset($_SERVER['SERVER_PROTOCOL'])) + { + return $_SERVER['SERVER_PROTOCOL']; + } + + return 'HTTP/1.0'; +} + //Form validation @@ -4771,7 +4795,7 @@ function phpbb_get_plural_form($rule, $number) * * @param array $param Parameter array, see $param_defaults array. * -* @return void +* @return null */ function phpbb_http_login($param) { @@ -5209,8 +5233,12 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 /** * Generate page footer +* +* @param bool $run_cron Whether or not to run the cron +* @param bool $display_template Whether or not to display the template +* @param bool $exit_handler Whether or not to run the exit_handler() */ -function page_footer($run_cron = true) +function page_footer($run_cron = true, $display_template = true, $exit_handler = true) { global $db, $config, $template, $user, $auth, $cache, $starttime, $phpbb_root_path, $phpEx; global $request, $phpbb_dispatcher; @@ -5305,10 +5333,17 @@ function page_footer($run_cron = true) } } - $template->display('body'); + if ($display_template) + { + $template->display('body'); + } garbage_collection(); - exit_handler(); + + if ($exit_handler) + { + exit_handler(); + } } /** @@ -5326,7 +5361,10 @@ function garbage_collection() * @event core.garbage_collection * @since 3.1-A1 */ - $phpbb_dispatcher->dispatch('core.garbage_collection'); + if (!empty($phpbb_dispatcher)) + { + $phpbb_dispatcher->dispatch('core.garbage_collection'); + } // Unload cache, must be done before the DB connection if closed if (!empty($cache)) @@ -5412,3 +5450,49 @@ function phpbb_to_numeric($input) { return ($input > PHP_INT_MAX) ? (float) $input : (int) $input; } + +/** +* Create a Symfony Request object from phpbb_request object +* +* @param phpbb_request $request Request object +* @return Request A Symfony Request object +*/ +function phpbb_create_symfony_request(phpbb_request $request) +{ + // This function is meant to sanitize the global input arrays + $sanitizer = function(&$value, $key) { + $type_cast_helper = new phpbb_request_type_cast_helper(); + $type_cast_helper->set_var($value, $value, gettype($value), true); + }; + + // We need to re-enable the super globals so we can access them here + $request->enable_super_globals(); + $get_parameters = $_GET; + $post_parameters = $_POST; + $server_parameters = $_SERVER; + $files_parameters = $_FILES; + $cookie_parameters = $_COOKIE; + // And now disable them again for security + $request->disable_super_globals(); + + array_walk_recursive($get_parameters, $sanitizer); + array_walk_recursive($post_parameters, $sanitizer); + + // Until we fix the issue with relative paths, we have to fake path info + // to allow urls like app.php?controller=foo/bar + $controller = $request->variable('controller', ''); + $path_info = '/' . $controller; + $request_uri = $server_parameters['REQUEST_URI']; + + // Remove the query string from REQUEST_URI + if ($pos = strpos($request_uri, '?')) + { + $request_uri = substr($request_uri, 0, $pos); + } + + // Add the path info (i.e. controller route) to the REQUEST_URI + $server_parameters['REQUEST_URI'] = $request_uri . $path_info; + $server_parameters['SCRIPT_NAME'] = ''; + + return new Request($get_parameters, $post_parameters, array(), $cookie_parameters, $files_parameters, $server_parameters); +} diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 5e2ee8c8f6..15930f9a2c 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -3308,7 +3308,7 @@ function obtain_latest_version_info($force_update = false, $warn_fail = false, $ * @param int $flag The binary flag which is OR-ed with the current column value * @param string $sql_more This string is attached to the sql query generated to update the table. * - * @return void + * @return null */ function enable_bitfield_column_flag($table_name, $column_name, $flag, $sql_more = '') { diff --git a/phpBB/includes/functions_download.php b/phpBB/includes/functions_download.php index b6371dbecc..fc6f1cc762 100644 --- a/phpBB/includes/functions_download.php +++ b/phpBB/includes/functions_download.php @@ -433,7 +433,7 @@ function set_modified_headers($stamp, $browser) * * @param bool $exit Whether to die or not. * -* @return void +* @return null */ function file_gc($exit = true) { diff --git a/phpBB/includes/functions_install.php b/phpBB/includes/functions_install.php index 7a799993db..ab6b3ea009 100644 --- a/phpBB/includes/functions_install.php +++ b/phpBB/includes/functions_install.php @@ -87,7 +87,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20 '2.0.x' => false, ), 'postgres' => array( - 'LABEL' => 'PostgreSQL 7.x/8.x', + 'LABEL' => 'PostgreSQL 8.3+', 'SCHEMA' => 'postgres', 'MODULE' => 'pgsql', 'DELIM' => ';', diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index cf03de08c4..a18aeddabd 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -651,64 +651,6 @@ class queue } /** - * Obtains exclusive lock on queue cache file. - * Returns resource representing the lock - */ - function lock() - { - // For systems that can't have two processes opening - // one file for writing simultaneously - if (file_exists($this->cache_file . '.lock')) - { - $mode = 'rb'; - } - else - { - $mode = 'wb'; - } - - $lock_fp = @fopen($this->cache_file . '.lock', $mode); - - if ($mode == 'wb') - { - if (!$lock_fp) - { - // Two processes may attempt to create lock file at the same time. - // Have the losing process try opening the lock file again for reading - // on the assumption that the winning process created it - $mode = 'rb'; - $lock_fp = @fopen($this->cache_file . '.lock', $mode); - } - else - { - // Only need to set mode when the lock file is written - @chmod($this->cache_file . '.lock', 0666); - } - } - - if ($lock_fp) - { - @flock($lock_fp, LOCK_EX); - } - - return $lock_fp; - } - - /** - * Releases lock on queue cache file, using resource obtained from lock() - */ - function unlock($lock_fp) - { - // lock() will return null if opening lock file, and thus locking, failed. - // Accept null values here so that client code does not need to check them - if ($lock_fp) - { - @flock($lock_fp, LOCK_UN); - fclose($lock_fp); - } - } - - /** * Process queue * Using lock file */ @@ -716,16 +658,24 @@ class queue { global $db, $config, $phpEx, $phpbb_root_path, $user; - $lock_fp = $this->lock(); + $lock = new phpbb_lock_flock($this->cache_file); + $lock->acquire(); - set_config('last_queue_run', time(), true); - - if (!file_exists($this->cache_file) || filemtime($this->cache_file) > time() - $config['queue_interval']) + // avoid races, check file existence once + $have_cache_file = file_exists($this->cache_file); + if (!$have_cache_file || $config['last_queue_run'] > time() - $config['queue_interval']) { - $this->unlock($lock_fp); + if (!$have_cache_file) + { + set_config('last_queue_run', time(), true); + } + + $lock->release(); return; } + set_config('last_queue_run', time(), true); + include($this->cache_file); foreach ($this->queue_data as $object => $data_ary) @@ -789,7 +739,7 @@ class queue break; default: - $this->unlock($lock_fp); + $lock->release(); return; } @@ -865,7 +815,7 @@ class queue } } - $this->unlock($lock_fp); + $lock->release(); } /** @@ -878,7 +828,8 @@ class queue return; } - $lock_fp = $this->lock(); + $lock = new phpbb_lock_flock($this->cache_file); + $lock->acquire(); if (file_exists($this->cache_file)) { @@ -905,7 +856,7 @@ class queue phpbb_chmod($this->cache_file, CHMOD_READ | CHMOD_WRITE); } - $this->unlock($lock_fp); + $lock->release(); } } diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index ad76be9f2f..0d387ace6d 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -759,7 +759,26 @@ class p_master } } - $u_title = $module_url . $delim . 'i=' . (($item_ary['cat']) ? $item_ary['id'] : $item_ary['name'] . (($item_ary['is_duplicate']) ? '&icat=' . $current_id : '') . '&mode=' . $item_ary['mode']); + $u_title = $module_url . $delim . 'i='; + // if the item has a name use it, else use its id + if (empty($item_ary['name'])) + { + $u_title .= $item_ary['id']; + } + else + { + // if the category has a name, then use it. + $u_title .= $item_ary['name']; + } + // If the item is not a category append the mode + if (!$item_ary['cat']) + { + if ($item_ary['is_duplicate']) + { + $u_title .= '&icat=' . $current_id; + } + $u_title .= '&mode=' . $item_ary['mode']; + } // Was not allowed in categories before - /*!$item_ary['cat'] && */ $u_title .= (isset($item_ary['url_extra'])) ? $item_ary['url_extra'] : ''; diff --git a/phpBB/includes/functions_url_matcher.php b/phpBB/includes/functions_url_matcher.php new file mode 100644 index 0000000000..7280cb74eb --- /dev/null +++ b/phpBB/includes/functions_url_matcher.php @@ -0,0 +1,106 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2005 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper; +use Symfony\Component\Routing\Matcher\UrlMatcher; +use Symfony\Component\Routing\RequestContext; + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Create a new UrlMatcher class and dump it into the cache file +* +* @param phpbb_extension_finder $finder Extension finder +* @param RequestContext $context Symfony RequestContext object +* @param string $root_path Root path +* @param string $php_ext PHP extension +* @return null +*/ +function phpbb_get_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) +{ + if (defined('DEBUG')) + { + return phpbb_create_url_matcher($finder, $context); + } + + if (!phpbb_url_matcher_dumped($root_path, $php_ext)) + { + phpbb_create_dumped_url_matcher($finder, $root_path, $php_ext); + } + + return phpbb_load_url_matcher($context, $root_path, $php_ext); +} + +/** +* Create a new UrlMatcher class and dump it into the cache file +* +* @param phpbb_extension_finder $finder Extension finder +* @param string $root_path Root path +* @param string $php_ext PHP extension +* @return null +*/ +function phpbb_create_dumped_url_matcher(phpbb_extension_finder $finder, $root_path, $php_ext) +{ + $provider = new phpbb_controller_provider(); + $routes = $provider->import_paths_from_finder($finder)->find(); + $dumper = new PhpMatcherDumper($routes); + $cached_url_matcher_dump = $dumper->dump(array( + 'class' => 'phpbb_url_matcher', + )); + + file_put_contents($root_path . 'cache/url_matcher' . $php_ext, $cached_url_matcher_dump); +} + +/** +* Create a non-cached UrlMatcher +* +* @param phpbb_extension_finder $finder Extension finder +* @param RequestContext $context Symfony RequestContext object +* @return UrlMatcher +*/ +function phpbb_create_url_matcher(phpbb_extension_finder $finder, RequestContext $context) +{ + $provider = new phpbb_controller_provider(); + $routes = $provider->import_paths_from_finder($finder)->find(); + return new UrlMatcher($routes, $context); +} + +/** +* Load the cached phpbb_url_matcher class +* +* @param RequestContext $context Symfony RequestContext object +* @param string $root_path Root path +* @param string $php_ext PHP extension +* @return phpbb_url_matcher +*/ +function phpbb_load_url_matcher(RequestContext $context, $root_path, $php_ext) +{ + require($root_path . 'cache/url_matcher' . $php_ext); + return new phpbb_url_matcher($context); +} + +/** +* Determine whether we have our dumped URL matcher +* +* The class is automatically dumped to the cache directory +* +* @param string $root_path Root path +* @param string $php_ext PHP extension +* @return bool True if it exists, false if not +*/ +function phpbb_url_matcher_dumped($root_path, $php_ext) +{ + return file_exists($root_path . 'cache/url_matcher' . $php_ext); +} diff --git a/phpBB/includes/lock/db.php b/phpBB/includes/lock/db.php index fa559d6887..6e94dd5a85 100644 --- a/phpBB/includes/lock/db.php +++ b/phpBB/includes/lock/db.php @@ -125,7 +125,7 @@ class phpbb_lock_db * Note: Attempting to release a lock that is already released, * that is, calling release() multiple times, is harmless. * - * @return void + * @return null */ public function release() { diff --git a/phpBB/includes/lock/flock.php b/phpBB/includes/lock/flock.php new file mode 100644 index 0000000000..97bc7dd2b9 --- /dev/null +++ b/phpBB/includes/lock/flock.php @@ -0,0 +1,133 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* File locking class +* @package phpBB3 +*/ +class phpbb_lock_flock +{ + /** + * Path to the file to which access is controlled + * + * @var string + */ + private $path; + + /** + * File pointer for the lock file + * @var string + */ + private $lock_fp; + + /** + * Constructor. + * + * You have to call acquire() to actually acquire the lock. + * + * @param string $path Path to the file to which access is controlled + */ + public function __construct($path) + { + $this->path = $path; + $this->lock_fp = null; + } + + /** + * Tries to acquire the lock. + * + * If the lock is already held by another process, this call will block + * until the other process releases the lock. If a lock is acquired and + * is not released before script finishes but the process continues to + * live (apache/fastcgi) then subsequent processes trying to acquire + * the same lock will be blocked forever. + * + * If the lock is already held by the same process via another instance + * of this class, this call will block forever. + * + * If flock function is disabled in php or fails to work, lock + * acquisition will fail and false will be returned. + * + * @return bool true if lock was acquired + * false otherwise + */ + public function acquire() + { + if ($this->lock_fp) + { + return false; + } + + // For systems that can't have two processes opening + // one file for writing simultaneously + if (file_exists($this->path . '.lock')) + { + $mode = 'rb'; + } + else + { + $mode = 'wb'; + } + + $this->lock_fp = @fopen($this->path . '.lock', $mode); + + if ($mode == 'wb') + { + if (!$this->lock_fp) + { + // Two processes may attempt to create lock file at the same time. + // Have the losing process try opening the lock file again for reading + // on the assumption that the winning process created it + $mode = 'rb'; + $this->lock_fp = @fopen($this->path . '.lock', $mode); + } + else + { + // Only need to set mode when the lock file is written + @chmod($this->path . '.lock', 0666); + } + } + + if ($this->lock_fp) + { + @flock($this->lock_fp, LOCK_EX); + } + + return (bool) $this->lock_fp; + } + + /** + * Releases the lock. + * + * The lock must have been previously obtained, that is, acquire() call + * was issued and returned true. + * + * Note: Attempting to release a lock that is already released, + * that is, calling release() multiple times, is harmless. + * + * @return null + */ + public function release() + { + if ($this->lock_fp) + { + @flock($this->lock_fp, LOCK_UN); + fclose($this->lock_fp); + $this->lock_fp = null; + } + } +} diff --git a/phpBB/includes/questionnaire/questionnaire.php b/phpBB/includes/questionnaire/questionnaire.php index f0fb8c3c06..2d29fe978e 100644 --- a/phpBB/includes/questionnaire/questionnaire.php +++ b/phpBB/includes/questionnaire/questionnaire.php @@ -70,7 +70,7 @@ class phpbb_questionnaire_data_collector /** * Collect info into the data property. * - * @return void + * @return null */ function collect() { diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 58a4dd7d6a..ff2e24aa05 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -86,6 +86,14 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $this->word_length = array('min' => $this->config['fulltext_mysql_min_word_len'], 'max' => $this->config['fulltext_mysql_max_word_len']); + /** + * Load the UTF tools + */ + if (!function_exists('utf8_strlen')) + { + include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); + } + $error = false; } @@ -230,7 +238,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base } else { - $tmp_split_words[] = $word . ' '; + $tmp_split_words[] = $word; } } if ($phrase) diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index 08f64735b6..2880610655 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -121,6 +121,14 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base } } + /** + * Load the UTF tools + */ + if (!function_exists('utf8_strlen')) + { + include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); + } + $error = false; } diff --git a/phpBB/includes/style/resource_locator.php b/phpBB/includes/style/resource_locator.php index 8658fe4a36..4cf767c062 100644 --- a/phpBB/includes/style/resource_locator.php +++ b/phpBB/includes/style/resource_locator.php @@ -44,7 +44,7 @@ class phpbb_style_resource_locator implements phpbb_template_locator * style directory, such as admin control panel templates. * @var string */ - public $template_path = 'template/'; + private $template_path; /** * Map from root index to handles to source template file paths. @@ -64,6 +64,16 @@ class phpbb_style_resource_locator implements phpbb_template_locator private $filenames = array(); /** + * Constructor. + * + * Sets default template path to template/. + */ + public function __construct() + { + $this->set_default_template_path(); + } + + /** * Sets the list of style paths * * These paths will be searched for style files in the provided order. @@ -94,6 +104,31 @@ class phpbb_style_resource_locator implements phpbb_template_locator } /** + * Sets the location of templates directory within style directories. + * + * The location must be a relative path, with a trailing slash. + * Typically it is one directory level deep, e.g. "template/". + * + * @param string $template_path Relative path to templates directory within style directories + * @return null + */ + public function set_template_path($template_path) + { + $this->template_path = $template_path; + } + + /** + * Sets the location of templates directory within style directories + * to the default, which is "template/". + * + * @return null + */ + public function set_default_template_path() + { + $this->template_path = 'template/'; + } + + /** * {@inheritDoc} */ public function set_filenames(array $filename_array) @@ -229,4 +264,85 @@ class phpbb_style_resource_locator implements phpbb_template_locator // search failed return $default_result; } + + /** + * Obtains filesystem path for a template file. + * + * The simplest use is specifying a single template file as a string + * in the first argument. This template file should be a basename + * of a template file in the selected style, or its parent styles + * if template inheritance is being utilized. + * + * Note: "selected style" is whatever style the style resource locator + * is configured for. + * + * The return value then will be a path, relative to the current + * directory or absolute, to the template file in the selected style + * or its closest parent. + * + * If the selected style does not have the template file being searched, + * (and if inheritance is involved, none of the parents have it either), + * false will be returned. + * + * Specifying true for $return_default will cause the function to + * return the first path which was checked for existence in the event + * that the template file was not found, instead of false. + * This is the path in the selected style itself, not any of its + * parents. + * + * $files can be given an array of templates instead of a single + * template. When given an array, the function will try to resolve + * each template in the array to a path, and will return the first + * path that exists, or false if none exist. + * + * If $files is an array and template inheritance is involved, first + * each of the files will be checked in the selected style, then each + * of the files will be checked in the immediate parent, and so on. + * + * If $return_full_path is false, then instead of returning a usable + * path (when the template is found) only the template's basename + * will be returned. This can be used to check which of the templates + * specified in $files exists. Naturally more than one template must + * be given in $files. + * + * This function works identically to get_first_file_location except + * it operates on a list of templates, not files. Practically speaking, + * the templates given in the first argument first are prepended with + * the template path (property in this class), then given to + * get_first_file_location for the rest of the processing. + * + * Templates given to this function can be relative paths for templates + * located in subdirectories of the template directories. The paths + * should be relative to the templates directory (template/ by default). + * + * @param string or array $files List of templates to locate. If there is only + * one template, $files can be a string to make code easier to read. + * @param bool $return_default Determines what to return if template does not + * exist. If true, function will return location where template is + * supposed to be. If false, function will return false. + * @param bool $return_full_path If true, function will return full path + * to template. If false, function will return template file name. + * This parameter can be used to check which one of set of template + * files is available. + * @return string or boolean Source template path if template exists or $return_default is + * true. False if template does not exist and $return_default is false + */ + public function get_first_template_location($templates, $return_default = false, $return_full_path = true) + { + // add template path prefix + $files = array(); + if (is_string($templates)) + { + $files[] = $this->template_path . $templates; + } + else + { + foreach ($templates as $template) + { + $files[] = $this->template_path . $template; + } + } + + return $this->get_first_file_location($files, $return_default, $return_full_path); + } } diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php index 36298b49ec..effd496fb9 100644 --- a/phpBB/includes/style/style.php +++ b/phpBB/includes/style/style.php @@ -110,7 +110,7 @@ class phpbb_style * * @param string $name Name of style, used for cache prefix. Examples: "admin", "prosilver" * @param array or string $paths Array of style paths, relative to current root directory - * @param string $template_path Path to templates, relative to style directory. False if path should not be changed. + * @param string $template_path Path to templates, relative to style directory. False if path should be set to default (templates/). */ public function set_custom_style($name, $paths, $template_path = false) { @@ -122,13 +122,17 @@ class phpbb_style $this->provider->set_styles($paths); $this->locator->set_paths($this->provider); - $this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_'; - if ($template_path !== false) { - $this->template->template_path = $this->locator->template_path = $template_path; + $this->locator->set_template_path($template_path); + } + else + { + $this->locator->set_default_template_path(); } + $this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_'; + return true; } diff --git a/phpBB/includes/template/compile.php b/phpBB/includes/template/compile.php index 82b301c1a2..22da21820e 100644 --- a/phpBB/includes/template/compile.php +++ b/phpBB/includes/template/compile.php @@ -58,6 +58,9 @@ class phpbb_template_compile */ public function compile_file_to_file($source_file, $compiled_file) { + $lock = new phpbb_lock_flock($compiled_file); + $lock->acquire(); + $source_handle = @fopen($source_file, 'rb'); $destination_handle = @fopen($compiled_file, 'wb'); @@ -66,16 +69,15 @@ class phpbb_template_compile return false; } - @flock($destination_handle, LOCK_EX); - $this->compile_stream_to_stream($source_handle, $destination_handle); @fclose($source_handle); - @flock($destination_handle, LOCK_UN); @fclose($destination_handle); phpbb_chmod($compiled_file, CHMOD_READ | CHMOD_WRITE); + $lock->release(); + clearstatcache(); return true; @@ -118,7 +120,7 @@ class phpbb_template_compile * * @param resource $source_stream Source stream * @param resource $dest_stream Destination stream - * @return void + * @return null */ private function compile_stream_to_stream($source_stream, $dest_stream) { diff --git a/phpBB/includes/template/locator.php b/phpBB/includes/template/locator.php index 01c79eec4e..42db91efb2 100644 --- a/phpBB/includes/template/locator.php +++ b/phpBB/includes/template/locator.php @@ -99,12 +99,54 @@ interface phpbb_template_locator public function get_source_file_for_handle($handle, $find_all = false); /** - * Locates source file path, accounting for styles tree and verifying that - * the path exists. + * Obtains a complete filesystem path for a file in a style. * - * Unlike previous functions, this function works without template handle - * and it can search for more than one file. If more than one file name is - * specified, it will return location of file that it finds first. + * This function traverses the style tree (selected style and + * its parents in order, if inheritance is being used) and finds + * the first file on the filesystem matching specified relative path, + * or the first of the specified paths if more than one path is given. + * + * This function can be used to determine filesystem path of any + * file under any style, with the consequence being that complete + * relative to the style directory path must be provided as an argument. + * + * In particular, this function can be used to locate templates + * and javascript files. + * + * For locating templates get_first_template_location should be used + * as it prepends the configured template path to the template basename. + * + * Note: "selected style" is whatever style the style resource locator + * is configured for. + * + * The return value then will be a path, relative to the current + * directory or absolute, to the first existing file in the selected + * style or its closest parent. + * + * If the selected style does not have the file being searched, + * (and if inheritance is involved, none of the parents have it either), + * false will be returned. + * + * Multiple files can be specified, in which case the first file in + * the list that can be found on the filesystem is returned. + * + * If multiple files are specified and inheritance is involved, + * first each of the specified files is checked in the selected style, + * then each of the specified files is checked in the immediate parent, + * etc. + * + * Specifying true for $return_default will cause the function to + * return the first path which was checked for existence in the event + * that the template file was not found, instead of false. + * This is always a path in the selected style itself, not any of its + * parents. + * + * If $return_full_path is false, then instead of returning a usable + * path (when the file is found) the file's path relative to the style + * directory will be returned. This is the same path as was given to + * the function as a parameter. This can be used to check which of the + * files specified in $files exists. Naturally this requires passing + * more than one file in $files. * * @param array $files List of files to locate. * @param bool $return_default Determines what to return if file does not diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 8a7dc6b2f3..5396ddbfad 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -75,12 +75,6 @@ class phpbb_template private $locator; /** - * Location of templates directory within style directories - * @var string - */ - public $template_path = 'template/'; - - /** * Constructor. * * @param string $phpbb_root_path phpBB root path @@ -95,7 +89,6 @@ class phpbb_template $this->config = $config; $this->user = $user; $this->locator = $locator; - $this->template_path = $this->locator->template_path; $this->context = $context; } @@ -459,74 +452,6 @@ class phpbb_template } /** - * Obtains filesystem path for a template file. - * - * The simplest use is specifying a single template file as a string - * in the first argument. This template file should be a basename - * of a template file in the selected style, or its parent styles - * if template inheritance is being utilized. - * - * Note: "selected style" is whatever style the style resource locator - * is configured for. - * - * The return value then will be a path, relative to the current - * directory or absolute, to the template file in the selected style - * or its closest parent. - * - * If the selected style does not have the template file being searched, - * (and if inheritance is involved, none of the parents have it either), - * false will be returned. - * - * Specifying true for $return_default will cause the function to - * return the first path which was checked for existence in the event - * that the template file was not found, instead of false. - * This is the path in the selected style itself, not any of its - * parents. - * - * $files can be given an array of templates instead of a single - * template. When given an array, the function will try to resolve - * each template in the array to a path, and will return the first - * path that exists, or false if none exist. - * - * If $return_full_path is false, then instead of returning a usable - * path (when the template is found) only the template's basename - * will be returned. This can be used to check which of the templates - * specified in $files exists, provided different file names are - * used for different templates. - * - * @param string or array $files List of templates to locate. If there is only - * one template, $files can be a string to make code easier to read. - * @param bool $return_default Determines what to return if template does not - * exist. If true, function will return location where template is - * supposed to be. If false, function will return false. - * @param bool $return_full_path If true, function will return full path - * to template. If false, function will return template file name. - * This parameter can be used to check which one of set of template - * files is available. - * @return string or boolean Source template path if template exists or $return_default is - * true. False if template does not exist and $return_default is false - */ - public function locate($files, $return_default = false, $return_full_path = true) - { - // add template path prefix - $templates = array(); - if (is_string($files)) - { - $templates[] = $this->template_path . $files; - } - else - { - foreach ($files as $file) - { - $templates[] = $this->template_path . $file; - } - } - - // use resource locator to find files - return $this->locator->get_first_file_location($templates, $return_default, $return_full_path); - } - - /** * Include JS file * * @param string $file file name diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index 2228bc7931..23892c2c8c 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -132,6 +132,36 @@ class ucp_prefs $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>'; $timezone_selects = phpbb_timezone_select($user, $data['tz'], true); + + // check if there are any user-selectable languages + $sql = 'SELECT COUNT(lang_id) as languages_count + FROM ' . LANG_TABLE; + $result = $db->sql_query($sql); + if ($db->sql_fetchfield('languages_count') > 1) + { + $s_more_languages = true; + } + else + { + $s_more_languages = false; + } + $db->sql_freeresult($result); + + // check if there are any user-selectable styles + $sql = 'SELECT COUNT(style_id) as styles_count + FROM ' . STYLES_TABLE . ' + WHERE style_active = 1'; + $result = $db->sql_query($sql); + if ($db->sql_fetchfield('styles_count') > 1) + { + $s_more_styles = true; + } + else + { + $s_more_styles = false; + } + $db->sql_freeresult($result); + $template->assign_vars(array( 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '', @@ -152,6 +182,9 @@ class ucp_prefs 'DEFAULT_DATEFORMAT' => $config['default_dateformat'], 'A_DEFAULT_DATEFORMAT' => addslashes($config['default_dateformat']), + 'S_MORE_LANGUAGES' => $s_more_languages, + 'S_MORE_STYLES' => $s_more_styles, + 'S_LANG_OPTIONS' => language_select($data['lang']), 'S_STYLE_OPTIONS' => ($config['override_user_style']) ? '' : style_select($data['style']), 'S_TZ_OPTIONS' => $timezone_selects['tz_select'], diff --git a/phpBB/index.php b/phpBB/index.php index 66e1b2114b..845d0f0c02 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -17,48 +17,12 @@ define('IN_PHPBB', true); $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './'; $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'common.' . $phpEx); +include($phpbb_root_path . 'includes/functions_display.' . $phpEx); // Start session management $user->session_begin(); $auth->acl($user->data); -$user->setup(); - -// Handle the display of extension front pages -if ($ext = $request->variable('ext', '')) -{ - $class = 'phpbb_ext_' . str_replace('/', '_', $ext) . '_controller'; - - if (!$phpbb_extension_manager->available($ext)) - { - send_status_line(404, 'Not Found'); - trigger_error($user->lang('EXTENSION_DOES_NOT_EXIST', $ext)); - } - else if (!$phpbb_extension_manager->enabled($ext)) - { - send_status_line(404, 'Not Found'); - trigger_error($user->lang('EXTENSION_DISABLED', $ext)); - } - else if (!class_exists($class)) - { - send_status_line(404, 'Not Found'); - trigger_error($user->lang('EXTENSION_CONTROLLER_MISSING', $ext)); - } - - $controller = new $class; - - if (!($controller instanceof phpbb_extension_controller_interface)) - { - send_status_line(500, 'Internal Server Error'); - trigger_error($user->lang('EXTENSION_CLASS_WRONG_TYPE', $class)); - } - - $controller->handle(); - exit_handler(); -} - -include($phpbb_root_path . 'includes/functions_display.' . $phpEx); - -$user->add_lang('viewforum'); +$user->setup('viewforum'); display_forums('', $config['load_moderators']); diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 9384850fe6..7df54ebc31 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -113,6 +113,7 @@ $phpbb_container = phpbb_create_dumped_container_unless_debug( ), array( new phpbb_di_pass_collection_pass(), + new phpbb_di_pass_kernel_pass(), ), $phpbb_root_path, $phpEx @@ -2309,6 +2310,26 @@ function change_database_data(&$no_updates, $version) } } + // Disable receiving pms for bots + $sql = 'SELECT user_id + FROM ' . BOTS_TABLE; + $result = $db->sql_query($sql); + + $bot_user_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $bot_user_ids[] = (int) $row['user_id']; + } + $db->sql_freeresult($result); + + if (!empty($bot_user_ids)) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_allow_pm = 0 + WHERE ' . $db->sql_in_set('user_id', $bot_user_ids); + _sql($sql, $errored, $error_ary); + } + $no_updates = false; break; @@ -2769,6 +2790,28 @@ function change_database_data(&$no_updates, $version) $config->set('site_home_text', ''); } + // PHPBB3-10601: Make inbox default. Add basename to ucp's pm category + + // Get the category wanted while checking, at the same time, if this has already been applied + $sql = 'SELECT module_id, module_basename + FROM ' . MODULES_TABLE . " + WHERE module_basename <> 'ucp_pm' AND + module_langname='UCP_PM' + "; + $result = $db->sql_query_limit($sql, 1); + + if ($row = $db->sql_fetchrow($result)) + { + // This update is still not applied. Applying it + + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_basename = 'ucp_pm' + WHERE module_id = " . (int) $row['module_id']; + + _sql($sql, $errored, $error_ary); + } + $db->sql_freeresult($result); + break; } } diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index f80b8b5661..4b2fa046bc 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -1478,8 +1478,14 @@ class install_install extends module foreach ($this->module_categories[$module_class] as $cat_name => $subs) { + $basename = ''; + // Check if this sub-category has a basename. If it has, use it. + if (isset($this->module_categories_basenames[$cat_name])) + { + $basename = $this->module_categories_basenames[$cat_name]; + } $module_data = array( - 'module_basename' => '', + 'module_basename' => $basename, 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => 0, @@ -1507,8 +1513,14 @@ class install_install extends module { foreach ($subs as $level2_name) { + $basename = ''; + // Check if this sub-category has a basename. If it has, use it. + if (isset($this->module_categories_basenames[$level2_name])) + { + $basename = $this->module_categories_basenames[$level2_name]; + } $module_data = array( - 'module_basename' => '', + 'module_basename' => $basename, 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => (int) $categories[$cat_name]['id'], @@ -1772,6 +1784,7 @@ class install_install extends module 'user_timezone' => 'UTC', 'user_dateformat' => $lang['default_dateformat'], 'user_allow_massemail' => 0, + 'user_allow_pm' => 0, ); $user_id = user_add($user_row); @@ -2115,6 +2128,9 @@ class install_install extends module 'UCP_ZEBRA' => null, ), ); + var $module_categories_basenames = array( + 'UCP_PM' => 'ucp_pm', + ); var $module_extras = array( 'acp' => array( diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index 8c044550f3..7f40015002 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -71,7 +71,7 @@ class install_update extends module function main($mode, $sub) { - global $style, $template, $phpEx, $phpbb_root_path, $user, $db, $config, $cache, $auth, $language; + global $phpbb_style, $template, $phpEx, $phpbb_root_path, $user, $db, $config, $cache, $auth, $language; global $request; $this->tpl_name = 'install_update'; diff --git a/phpBB/language/en/acp/board.php b/phpBB/language/en/acp/board.php index a4380486cc..1b99c87938 100644 --- a/phpBB/language/en/acp/board.php +++ b/phpBB/language/en/acp/board.php @@ -449,10 +449,10 @@ $lang = array_merge($lang, array( 'ACP_SECURITY_SETTINGS_EXPLAIN' => 'Here you are able to define session and login related settings.', 'ALL' => 'All', - 'ALLOW_AUTOLOGIN' => 'Allow persistent logins', - 'ALLOW_AUTOLOGIN_EXPLAIN' => 'Determines whether users can autologin when they visit the board.', - 'AUTOLOGIN_LENGTH' => 'Persistent login key expiration length (in days)', - 'AUTOLOGIN_LENGTH_EXPLAIN' => 'Number of days after which persistent login keys are removed or zero to disable.', + 'ALLOW_AUTOLOGIN' => 'Allow "Remember Me" logins', + 'ALLOW_AUTOLOGIN_EXPLAIN' => 'Determines whether users are given "Remember Me" option when they visit the board.', + 'AUTOLOGIN_LENGTH' => '"Remember Me" login key expiration length (in days)', + 'AUTOLOGIN_LENGTH_EXPLAIN' => 'Number of days after which "Remember Me" login keys are removed or zero to disable.', 'BROWSER_VALID' => 'Validate browser', 'BROWSER_VALID_EXPLAIN' => 'Enables browser validation for each session improving security.', 'CHECK_DNSBL' => 'Check IP against DNS Blackhole List', diff --git a/phpBB/language/en/app.php b/phpBB/language/en/app.php new file mode 100644 index 0000000000..cb56015c30 --- /dev/null +++ b/phpBB/language/en/app.php @@ -0,0 +1,49 @@ +<?php +/** +* +* app [English] +* +* @package language +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* DO NOT CHANGE +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +if (empty($lang) || !is_array($lang)) +{ + $lang = array(); +} + +// DEVELOPERS PLEASE NOTE +// +// All language files should use UTF-8 as their encoding and the files must not contain a BOM. +// +// Placeholders can now contain order information, e.g. instead of +// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows +// translators to re-order the output of data while ensuring it remains correct +// +// You do not need this where single placeholders are used, e.g. 'Message %d' is fine +// equally where a string contains only two placeholders which are used to wrap text +// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine +// +// Some characters you may want to copy&paste: +// ’ » “ ” … +// + +$lang = array_merge($lang, array( + 'CONTROLLER_ARGUMENT_VALUE_MISSING' => 'Missing value for argument #%1$s: <strong>%3$s</strong> in class <strong>%2$s</strong>', + 'CONTROLLER_NOT_SPECIFIED' => 'No controller has been specified.', + 'CONTROLLER_NOT_FOUND' => 'The requested page could not be found.', + 'CONTROLLER_METHOD_NOT_SPECIFIED' => 'No method was specified for the controller.', + 'CONTROLLER_SERVICE_NOT_GIVEN' => 'The controller "<strong>%s</strong>" must have a service specified in ./config/routing.yml.', + 'CONTROLLER_SERVICE_UNDEFINED' => 'The service for controller "<strong>%s</strong>" is not defined in ./config/services.yml.', + 'CONTROLLER_RETURN_TYPE_INVALID' => 'The controller object <strong>%s</strong> must return a Symfony\Component\HttpFoundation\Response object.', +)); diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 4300ef431a..fbb7b40d41 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -343,7 +343,7 @@ $lang = array_merge($lang, array( 'LOGIN_EXPLAIN_VIEWONLINE' => 'In order to view the online list you have to be registered and logged in.', 'LOGOUT' => 'Logout', 'LOGOUT_USER' => 'Logout [ %s ]', - 'LOG_ME_IN' => 'Log me on automatically each visit', + 'LOG_ME_IN' => 'Remember me', 'MARK' => 'Mark', 'MARK_ALL' => 'Mark all', @@ -605,9 +605,11 @@ $lang = array_merge($lang, array( 'SUBJECT' => 'Subject', 'SUBMIT' => 'Submit', + 'TB' => 'TB', 'TERMS_USE' => 'Terms of use', 'TEST_CONNECTION' => 'Test connection', 'THE_TEAM' => 'The team', + 'TIB' => 'TiB', 'TIME' => 'Time', 'TIMEOUT_PROCESSING_REQ' => 'Request timed out.', diff --git a/phpBB/language/en/help_faq.php b/phpBB/language/en/help_faq.php index 5c99f81c06..9500943b88 100644 --- a/phpBB/language/en/help_faq.php +++ b/phpBB/language/en/help_faq.php @@ -43,7 +43,7 @@ $help = array( ), array( 0 => 'Why do I get logged off automatically?', - 1 => 'If you do not check the <em>Log me in automatically</em> box when you login, the board will only keep you logged in for a preset time. This prevents misuse of your account by anyone else. To stay logged in, check the box during login. This is not recommended if you access the board from a shared computer, e.g. library, internet cafe, university computer lab, etc. If you do not see this checkbox, it means the board administrator has disabled this feature.' + 1 => 'If you do not check the <em>Remember me</em> box when you login, the board will only keep you logged in for a preset time. This prevents misuse of your account by anyone else. To stay logged in, check the box during login. This is not recommended if you access the board from a shared computer, e.g. library, internet cafe, university computer lab, etc. If you do not see this checkbox, it means the board administrator has disabled this feature.' ), array( 0 => 'How do I prevent my username appearing in the online user listings?', diff --git a/phpBB/language/en/install.php b/phpBB/language/en/install.php index cb6a17afa2..1c45deae11 100644 --- a/phpBB/language/en/install.php +++ b/phpBB/language/en/install.php @@ -210,7 +210,7 @@ $lang = array_merge($lang, array( <p>phpBB3 supports the following databases:</p> <ul> <li>MySQL 3.23 or above (MySQLi supported)</li> - <li>PostgreSQL 7.3+</li> + <li>PostgreSQL 8.3+</li> <li>SQLite 2.8.2+</li> <li>Firebird 2.1+</li> <li>MS SQL Server 2000 or above (directly or via ODBC)</li> diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index 705b07b170..b919699ea0 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -87,7 +87,7 @@ $lang = array_merge($lang, array( 'ATTACHMENTS_EXPLAIN' => 'This is a list of attachments you have made in posts to this board.', 'ATTACHMENTS_DELETED' => 'Attachments successfully deleted.', 'ATTACHMENT_DELETED' => 'Attachment successfully deleted.', - 'AUTOLOGIN_SESSION_KEYS_DELETED'=> 'The selected persistent login keys were successfully deleted.', + 'AUTOLOGIN_SESSION_KEYS_DELETED'=> 'The selected "Remember Me" login keys were successfully deleted.', 'AVATAR_CATEGORY' => 'Category', 'AVATAR_EXPLAIN' => 'Maximum dimensions; width: %1$s, height: %2$s, file size: %3$.2f KiB.', 'AVATAR_FEATURES_DISABLED' => 'The avatar functionality is currently disabled.', @@ -380,8 +380,8 @@ $lang = array_merge($lang, array( 'PREFERENCES_UPDATED' => 'Your preferences have been updated.', 'PROFILE_INFO_NOTICE' => 'Please note that this information may be viewable to other members. Be careful when including any personal details. Any fields marked with a * must be completed.', 'PROFILE_UPDATED' => 'Your profile has been updated.', - 'PROFILE_AUTOLOGIN_KEYS' => 'The persistent login keys automatically log you in when you visit the board. If you logout, the persistent login key is deleted only on the computer you are using to logout. Here you can see persistent login keys created on other computers you used to access this site.', - 'PROFILE_NO_AUTOLOGIN_KEYS' => 'There are no saved persistent login keys.', + 'PROFILE_AUTOLOGIN_KEYS' => 'The "Remember Me" login keys automatically log you in when you visit the board. If you logout, the remember me login key is deleted only on the computer you are using to logout. Here you can see remember login keys created on other computers you used to access this site.', + 'PROFILE_NO_AUTOLOGIN_KEYS' => 'There are no saved "Remember Me" login keys.', 'RECIPIENT' => 'Recipient', 'RECIPIENTS' => 'Recipients', @@ -476,7 +476,7 @@ $lang = array_merge($lang, array( 'UCP_PROFILE_PROFILE_INFO' => 'Edit profile', 'UCP_PROFILE_REG_DETAILS' => 'Edit account settings', 'UCP_PROFILE_SIGNATURE' => 'Edit signature', - 'UCP_PROFILE_AUTOLOGIN_KEYS'=> 'Edit persistent login keys', + 'UCP_PROFILE_AUTOLOGIN_KEYS'=> 'Edit "Remember Me" login keys', 'UCP_USERGROUPS' => 'Usergroups', 'UCP_USERGROUPS_MEMBER' => 'Edit memberships', diff --git a/phpBB/styles/prosilver/template/overall_header.html b/phpBB/styles/prosilver/template/overall_header.html index 79a8b07971..3e00827235 100644 --- a/phpBB/styles/prosilver/template/overall_header.html +++ b/phpBB/styles/prosilver/template/overall_header.html @@ -120,7 +120,8 @@ <div class="inner"> <ul class="linklist navlinks"> - <li class="icon-home"><!-- IF U_SITE_HOME --><a href="{U_SITE_HOME}">{L_SITE_HOME}</a> <strong>‹</strong> <!-- ENDIF --><a href="{U_INDEX}" accesskey="h">{L_INDEX}</a> <!-- BEGIN navlinks --> <strong>‹</strong> <a href="{navlinks.U_VIEW_FORUM}">{navlinks.FORUM_NAME}</a><!-- END navlinks --></li> + <!-- DEFINE $MICRODATA = ' itemtype="http://data-vocabulary.org/Breadcrumb" itemscope=""' --> + <li class="icon-home"><!-- IF U_SITE_HOME --><a href="{U_SITE_HOME}"{$MICRODATA}>{L_SITE_HOME}</a> <strong>‹</strong> <!-- ENDIF --><a href="{U_INDEX}" accesskey="h"{$MICRODATA}>{L_INDEX}</a> <!-- BEGIN navlinks --> <strong>‹</strong> <a href="{navlinks.U_VIEW_FORUM}"{$MICRODATA}>{navlinks.FORUM_NAME}</a><!-- END navlinks --></li> <!-- IF U_EMAIL_TOPIC --><li class="rightside"><a href="{U_EMAIL_TOPIC}" title="{L_EMAIL_TOPIC}" class="sendemail">{L_EMAIL_TOPIC}</a></li><!-- ENDIF --> <!-- IF U_EMAIL_PM --><li class="rightside"><a href="{U_EMAIL_PM}" title="{L_EMAIL_PM}" class="sendemail">{L_EMAIL_PM}</a></li><!-- ENDIF --> diff --git a/phpBB/styles/prosilver/template/ucp_prefs_personal.html b/phpBB/styles/prosilver/template/ucp_prefs_personal.html index 4382e891fd..50ade02acd 100644 --- a/phpBB/styles/prosilver/template/ucp_prefs_personal.html +++ b/phpBB/styles/prosilver/template/ucp_prefs_personal.html @@ -63,11 +63,13 @@ <label for="popuppm0"><input type="radio" name="popuppm" id="popuppm0" value="0"<!-- IF not S_POPUP_PM --> checked="checked"<!-- ENDIF --> /> {L_NO}</label> </dd> </dl> - <dl> - <dt><label for="lang">{L_BOARD_LANGUAGE}{L_COLON}</label></dt> - <dd><select name="lang" id="lang">{S_LANG_OPTIONS}</select></dd> - </dl> - <!-- IF S_STYLE_OPTIONS --> + <!-- IF S_MORE_LANGUAGES --> + <dl> + <dt><label for="lang">{L_BOARD_LANGUAGE}{L_COLON}</label></dt> + <dd><select name="lang" id="lang">{S_LANG_OPTIONS}</select></dd> + </dl> + <!-- ENDIF --> + <!-- IF S_STYLE_OPTIONS and S_MORE_STYLES --> <dl> <dt><label for="style">{L_BOARD_STYLE}{L_COLON}</label></dt> <dd><select name="style" id="style">{S_STYLE_OPTIONS}</select></dd> diff --git a/phpBB/styles/subsilver2/template/breadcrumbs.html b/phpBB/styles/subsilver2/template/breadcrumbs.html index 73386ed851..49e31c0749 100644 --- a/phpBB/styles/subsilver2/template/breadcrumbs.html +++ b/phpBB/styles/subsilver2/template/breadcrumbs.html @@ -1,7 +1,8 @@ + <!-- IF $S_MICRODATA --><!-- DEFINE $MICRODATA = ' itemtype="http://data-vocabulary.org/Breadcrumb" itemscope=""' --><!-- ELSE --><!-- DEFINE $MICRODATA = '' --><!-- ENDIF --> <table class="tablebg" width="100%" cellspacing="1" cellpadding="0" style="margin-top: 5px;"> <tr> <td class="row1"> - <p class="breadcrumbs"><!-- IF U_SITE_HOME --><a href="{U_SITE_HOME}">{L_SITE_HOME}</a> <strong>»</strong> <!-- ENDIF --><a href="{U_INDEX}">{L_INDEX}</a><!-- BEGIN navlinks --> » <a href="{navlinks.U_VIEW_FORUM}">{navlinks.FORUM_NAME}</a><!-- END navlinks --></p> + <p class="breadcrumbs"><!-- IF U_SITE_HOME --><a href="{U_SITE_HOME}"{$MICRODATA}>{L_SITE_HOME}</a> <strong>»</strong> <!-- ENDIF --><a href="{U_INDEX}"{$MICRODATA}>{L_INDEX}</a><!-- BEGIN navlinks --> » <a href="{navlinks.U_VIEW_FORUM}"{$MICRODATA}>{navlinks.FORUM_NAME}</a><!-- END navlinks --></p> <p class="datetime">{S_TIMEZONE}</p> </td> </tr> diff --git a/phpBB/styles/subsilver2/template/overall_header.html b/phpBB/styles/subsilver2/template/overall_header.html index e93dd056bf..4ed69c56aa 100644 --- a/phpBB/styles/subsilver2/template/overall_header.html +++ b/phpBB/styles/subsilver2/template/overall_header.html @@ -195,6 +195,8 @@ function marklist(id, name, state) <br style="clear: both;" /> + <!-- DEFINE $S_MICRODATA = 1 --> <!-- INCLUDE breadcrumbs.html --> + <!-- DEFINE $S_MICRODATA = 0 --> <br /> diff --git a/phpBB/styles/subsilver2/template/ucp_prefs_personal.html b/phpBB/styles/subsilver2/template/ucp_prefs_personal.html index 5a169763fb..9ebc045608 100644 --- a/phpBB/styles/subsilver2/template/ucp_prefs_personal.html +++ b/phpBB/styles/subsilver2/template/ucp_prefs_personal.html @@ -61,11 +61,13 @@ <td class="row1" width="50%"><b class="genmed">{L_POPUP_ON_PM}{L_COLON}</b></td> <td class="row2"><input type="radio" class="radio" name="popuppm" value="1"<!-- IF S_POPUP_PM --> checked="checked"<!-- ENDIF --> /><span class="genmed">{L_YES}</span> <input type="radio" class="radio" name="popuppm" value="0"<!-- IF not S_POPUP_PM --> checked="checked"<!-- ENDIF --> /><span class="genmed">{L_NO}</span></td> </tr> +<!-- IF S_MORE_LANGUAGES --> <tr> <td class="row1" width="50%"><b class="genmed">{L_BOARD_LANGUAGE}{L_COLON}</b></td> <td class="row2"><select name="lang">{S_LANG_OPTIONS}</select></td> </tr> -<!-- IF S_STYLE_OPTIONS --> +<!-- ENDIF --> +<!-- IF S_STYLE_OPTIONS and S_MORE_STYLES --> <tr> <td class="row1" width="50%"><b class="genmed">{L_BOARD_STYLE}{L_COLON}</b></td> <td class="row2"><select name="style">{S_STYLE_OPTIONS}</select></td> diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt index 7c2a7c3fce..75a6fc94f6 100644 --- a/tests/RUNNING_TESTS.txt +++ b/tests/RUNNING_TESTS.txt @@ -72,6 +72,21 @@ to connect to that database in phpBB. Additionally, you will need to be running the DbUnit fork from https://github.com/phpbb/dbunit/tree/phpbb. +Redis +----- + +In order to run tests for the Redis cache driver, at least one of Redis host +or port must be specified in test configuration. This can be done via +test_config.php as follows: + + <?php + $phpbb_redis_host = 'localhost'; + $phpbb_redis_port = 6379; + +Or via environment variables as follows: + + $ PHPBB_TEST_REDIS_HOST=localhost PHPBB_TEST_REDIS_PORT=6379 phpunit + Running ======= diff --git a/tests/cache/apc_driver_test.php b/tests/cache/apc_driver_test.php new file mode 100644 index 0000000000..3380762878 --- /dev/null +++ b/tests/cache/apc_driver_test.php @@ -0,0 +1,53 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +// Important: apc.enable_cli=1 must be in php.ini. +// http://forums.devshed.com/php-development-5/apc-problem-561290.html +// http://php.net/manual/en/apc.configuration.php + +require_once dirname(__FILE__) . '/common_test_case.php'; + +class phpbb_cache_apc_driver_test extends phpbb_cache_common_test_case +{ + protected static $config; + protected $driver; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); + } + + static public function setUpBeforeClass() + { + if (!extension_loaded('apc')) + { + self::markTestSkipped('APC extension is not loaded'); + } + + $php_ini = new phpbb_php_ini; + + if (!$php_ini->get_bool('apc.enabled')) + { + self::markTestSkipped('APC is not enabled. Make sure apc.enabled=1 in php.ini'); + } + + if (PHP_SAPI == 'cli' && !$php_ini->get_bool('apc.enable_cli')) + { + self::markTestSkipped('APC is not enabled for CLI. Set apc.enable_cli=1 in php.ini'); + } + } + + protected function setUp() + { + parent::setUp(); + + $this->driver = new phpbb_cache_driver_apc; + $this->driver->purge(); + } +} diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php deleted file mode 100644 index c5f5fac88c..0000000000 --- a/tests/cache/cache_test.php +++ /dev/null @@ -1,109 +0,0 @@ -<?php -/** -* -* @package testing -* @copyright (c) 2010 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_cache_test extends phpbb_database_test_case -{ - private $cache_dir; - - public function __construct() - { - $this->cache_dir = dirname(__FILE__) . '/../tmp/cache/'; - } - - public function getDataSet() - { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); - } - - protected function setUp() - { - parent::setUp(); - - if (file_exists($this->cache_dir)) - { - // cache directory possibly left after aborted - // or failed run earlier - $this->remove_cache_dir(); - } - $this->create_cache_dir(); - } - - protected function tearDown() - { - if (file_exists($this->cache_dir)) - { - $this->remove_cache_dir(); - } - - parent::tearDown(); - } - - private function create_cache_dir() - { - $this->get_test_case_helpers()->makedirs($this->cache_dir); - } - - private function remove_cache_dir() - { - $iterator = new DirectoryIterator($this->cache_dir); - foreach ($iterator as $file) - { - if ($file != '.' && $file != '..') - { - unlink($this->cache_dir . '/' . $file); - } - } - rmdir($this->cache_dir); - } - - public function test_cache_driver_file() - { - $driver = new phpbb_cache_driver_file($this->cache_dir); - $driver->put('test_key', 'test_value'); - $driver->save(); - - $this->assertEquals( - 'test_value', - $driver->get('test_key'), - 'File ACM put and get' - ); - } - - public function test_cache_sql() - { - $driver = new phpbb_cache_driver_file($this->cache_dir); - - global $db, $cache; - $db = $this->new_dbal(); - $cache = new phpbb_cache_service($driver); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql, 300); - $first_result = $db->sql_fetchrow($result); - - $this->assertFileExists($this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php'); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql, 300); - - $this->assertEquals($first_result, $db->sql_fetchrow($result)); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'bar'"; - $result = $db->sql_query($sql, 300); - - $this->assertNotEquals($first_result, $db->sql_fetchrow($result)); - - $db->sql_close(); - } -} diff --git a/tests/cache/common_test_case.php b/tests/cache/common_test_case.php new file mode 100644 index 0000000000..fa298ec9ae --- /dev/null +++ b/tests/cache/common_test_case.php @@ -0,0 +1,97 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +abstract class phpbb_cache_common_test_case extends phpbb_database_test_case +{ + public function test_get_put_exists() + { + $this->assertFalse($this->driver->_exists('test_key')); + $this->assertSame(false, $this->driver->get('test_key')); + + $this->driver->put('test_key', 'test_value'); + + $this->assertTrue($this->driver->_exists('test_key')); + $this->assertEquals( + 'test_value', + $this->driver->get('test_key'), + 'File ACM put and get' + ); + } + + public function test_purge() + { + $this->driver->put('test_key', 'test_value'); + + $this->assertEquals( + 'test_value', + $this->driver->get('test_key'), + 'File ACM put and get' + ); + + $this->driver->purge(); + + $this->assertSame(false, $this->driver->get('test_key')); + } + + public function test_destroy() + { + $this->driver->put('first_key', 'first_value'); + $this->driver->put('second_key', 'second_value'); + + $this->assertEquals( + 'first_value', + $this->driver->get('first_key') + ); + $this->assertEquals( + 'second_value', + $this->driver->get('second_key') + ); + + $this->driver->destroy('first_key'); + + $this->assertFalse($this->driver->_exists('first_key')); + $this->assertEquals( + 'second_value', + $this->driver->get('second_key') + ); + } + + public function test_cache_sql() + { + global $db, $cache; + $db = $this->new_dbal(); + $cache = new phpbb_cache_service($this->driver); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + + $result = $db->sql_query($sql, 300); + $first_result = $db->sql_fetchrow($result); + $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); + $this->assertEquals($expected, $first_result); + + $sql = 'DELETE FROM phpbb_config'; + $result = $db->sql_query($sql); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + + $this->assertEquals($expected, $db->sql_fetchrow($result)); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql); + + $no_cache_result = $db->sql_fetchrow($result); + $this->assertSame(false, $no_cache_result); + + $db->sql_close(); + } +} diff --git a/tests/cache/file_driver_test.php b/tests/cache/file_driver_test.php new file mode 100644 index 0000000000..745c6bb081 --- /dev/null +++ b/tests/cache/file_driver_test.php @@ -0,0 +1,69 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/common_test_case.php'; + +class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case +{ + private $cache_dir; + protected $driver; + + public function __construct() + { + $this->cache_dir = dirname(__FILE__) . '/../tmp/cache/'; + } + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); + } + + protected function setUp() + { + parent::setUp(); + + if (file_exists($this->cache_dir)) + { + // cache directory possibly left after aborted + // or failed run earlier + $this->remove_cache_dir(); + } + $this->create_cache_dir(); + + $this->driver = new phpbb_cache_driver_file($this->cache_dir); + } + + protected function tearDown() + { + if (file_exists($this->cache_dir)) + { + $this->remove_cache_dir(); + } + + parent::tearDown(); + } + + private function create_cache_dir() + { + $this->get_test_case_helpers()->makedirs($this->cache_dir); + } + + private function remove_cache_dir() + { + $iterator = new DirectoryIterator($this->cache_dir); + foreach ($iterator as $file) + { + if ($file != '.' && $file != '..') + { + unlink($this->cache_dir . '/' . $file); + } + } + rmdir($this->cache_dir); + } +} diff --git a/tests/cache/null_driver_test.php b/tests/cache/null_driver_test.php new file mode 100644 index 0000000000..86553d4dc5 --- /dev/null +++ b/tests/cache/null_driver_test.php @@ -0,0 +1,74 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_cache_null_driver_test extends phpbb_database_test_case +{ + protected $driver; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->driver = new phpbb_cache_driver_null; + } + + public function test_get_put() + { + $this->assertSame(false, $this->driver->get('key')); + + $this->driver->put('key', 'value'); + + // null driver does not cache + $this->assertSame(false, $this->driver->get('key')); + } + + public function test_purge() + { + // does nothing + $this->driver->purge(); + } + + public function test_destroy() + { + // does nothing + $this->driver->destroy('foo'); + } + + public function test_cache_sql() + { + global $db, $cache; + $db = $this->new_dbal(); + $cache = new phpbb_cache_service($this->driver); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + $first_result = $db->sql_fetchrow($result); + $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); + $this->assertEquals($expected, $first_result); + + $sql = 'DELETE FROM phpbb_config'; + $result = $db->sql_query($sql); + + // As null cache driver does not actually cache, + // this should return no results + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + + $this->assertSame(false, $db->sql_fetchrow($result)); + + $db->sql_close(); + } +} diff --git a/tests/cache/redis_driver_test.php b/tests/cache/redis_driver_test.php new file mode 100644 index 0000000000..1308519a18 --- /dev/null +++ b/tests/cache/redis_driver_test.php @@ -0,0 +1,49 @@ +<?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__) . '/common_test_case.php'; + +class phpbb_cache_redis_driver_test extends phpbb_cache_common_test_case +{ + protected static $config; + protected $driver; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); + } + + static public function setUpBeforeClass() + { + if (!extension_loaded('redis')) + { + self::markTestSkipped('redis extension is not loaded'); + } + + $config = phpbb_test_case_helpers::get_test_config(); + if (isset($config['redis_host']) || isset($config['redis_port'])) + { + $host = isset($config['redis_host']) ? $config['redis_host'] : 'localhost'; + $port = isset($config['redis_port']) ? $config['redis_port'] : 6379; + self::$config = array('host' => $host, 'port' => $port); + } + else + { + self::markTestSkipped('Test redis host/port is not specified'); + } + } + + protected function setUp() + { + parent::setUp(); + + $this->driver = new phpbb_cache_driver_redis(self::$config['host'], self::$config['port']); + $this->driver->purge(); + } +} diff --git a/tests/controller/config/routing.yml b/tests/controller/config/routing.yml new file mode 100644 index 0000000000..175b11f130 --- /dev/null +++ b/tests/controller/config/routing.yml @@ -0,0 +1,3 @@ +core_controller: + pattern: /core_foo + defaults: { _controller: core_foo.controller:bar } diff --git a/tests/controller/config/services.yml b/tests/controller/config/services.yml new file mode 100644 index 0000000000..f1bd047489 --- /dev/null +++ b/tests/controller/config/services.yml @@ -0,0 +1,3 @@ +services: + core_foo.controller: + class: phpbb_controller_foo diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php new file mode 100644 index 0000000000..198fb3c6dd --- /dev/null +++ b/tests/controller/controller_test.php @@ -0,0 +1,76 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\Route; +use Symfony\Component\Routing\RouteCollection; +use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; + +class phpbb_controller_test extends phpbb_test_case +{ + public function setUp() + { + $this->extension_manager = new phpbb_mock_extension_manager( + dirname(__FILE__) . '/', + array( + 'foo' => array( + 'ext_name' => 'foo', + 'ext_active' => '1', + 'ext_path' => 'ext/foo/', + ), + )); + } + + public function test_provider() + { + $provider = new phpbb_controller_provider; + $routes = $provider + ->import_paths_from_finder($this->extension_manager->get_finder()) + ->find('./tests/controller/'); + + // This will need to be updated if any new routes are defined + $this->assertEquals(2, sizeof($routes)); + } + + public function test_controller_resolver() + { + $container = new ContainerBuilder(); + // YamlFileLoader only uses one path at a time, so we need to loop + // through all of the ones we are using. + foreach (array(__DIR__.'/config', __DIR__.'/ext/foo/config') as $path) + { + $loader = new YamlFileLoader($container, new FileLocator($path)); + $loader->load('services.yml'); + } + + // Autoloading classes within the tests folder does not work + // so I'll include them manually. + if (!class_exists('phpbb_ext_foo_controller')) + { + include(__DIR__.'/ext/foo/controller.php'); + } + if (!class_exists('phpbb_controller_foo')) + { + include(__DIR__.'/includes/controller/foo.php'); + } + + $resolver = new phpbb_controller_resolver(new phpbb_user, $container); + $symfony_request = new Request(); + $symfony_request->attributes->set('_controller', 'foo.controller:handle'); + + $this->assertEquals($resolver->getController($symfony_request), array(new phpbb_ext_foo_controller, 'handle')); + + $symfony_request = new Request(); + $symfony_request->attributes->set('_controller', 'core_foo.controller:bar'); + + $this->assertEquals($resolver->getController($symfony_request), array(new phpbb_controller_foo, 'bar')); + } +} diff --git a/tests/controller/ext/foo/config/routing.yml b/tests/controller/ext/foo/config/routing.yml new file mode 100644 index 0000000000..4799fec37d --- /dev/null +++ b/tests/controller/ext/foo/config/routing.yml @@ -0,0 +1,3 @@ +controller1: + pattern: /foo + defaults: { _controller: foo.controller:handle } diff --git a/tests/controller/ext/foo/config/services.yml b/tests/controller/ext/foo/config/services.yml new file mode 100644 index 0000000000..ce0e18c610 --- /dev/null +++ b/tests/controller/ext/foo/config/services.yml @@ -0,0 +1,3 @@ +services: + foo.controller: + class: phpbb_ext_foo_controller diff --git a/tests/controller/ext/foo/controller.php b/tests/controller/ext/foo/controller.php new file mode 100644 index 0000000000..cfc5c20622 --- /dev/null +++ b/tests/controller/ext/foo/controller.php @@ -0,0 +1,16 @@ +<?php + +use Symfony\Component\HttpFoundation\Response; + +class phpbb_ext_foo_controller +{ + /** + * Handle method + * + * @return null + */ + public function handle() + { + return new Response('Test', 200); + } +} diff --git a/tests/controller/includes/controller/foo.php b/tests/controller/includes/controller/foo.php new file mode 100644 index 0000000000..04576e16c4 --- /dev/null +++ b/tests/controller/includes/controller/foo.php @@ -0,0 +1,16 @@ +<?php + +use Symfony\Component\HttpFoundation\Response; + +class phpbb_controller_foo +{ + /** + * Bar method + * + * @return null + */ + public function bar() + { + return new Response('bar()', 200); + } +} diff --git a/tests/dbal/write_sequence_test.php b/tests/dbal/write_sequence_test.php new file mode 100644 index 0000000000..8975cfbfb1 --- /dev/null +++ b/tests/dbal/write_sequence_test.php @@ -0,0 +1,55 @@ +<?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_write_sequence_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/three_users.xml'); + } + + static public function write_sequence_data() + { + return array( + array( + 'ticket/11219', + 4, + ), + ); + } + + /** + * @dataProvider write_sequence_data + */ + public function test_write_sequence($username, $expected) + { + $db = $this->new_dbal(); + + $sql = 'INSERT INTO phpbb_users ' . $db->sql_build_array('INSERT', array( + 'username' => $username, + 'username_clean' => $username, + 'user_permissions' => '', + 'user_sig' => '', + 'user_occ' => '', + 'user_interests' => '', + )); + $db->sql_query($sql); + + $this->assertEquals($expected, $db->sql_nextid()); + + $sql = "SELECT user_id + FROM phpbb_users + WHERE username_clean = '" . $db->sql_escape($username) . "'"; + $result = $db->sql_query_limit($sql, 1); + + $this->assertEquals($expected, $db->sql_fetchfield('user_id')); + } +} diff --git a/tests/fixtures/empty.xml b/tests/fixtures/empty.xml new file mode 100644 index 0000000000..96eb1ab483 --- /dev/null +++ b/tests/fixtures/empty.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_posts"> + </table> +</dataset> diff --git a/tests/functional/browse_test.php b/tests/functional/browse_test.php index 26c18c4c1f..b5748059c6 100644 --- a/tests/functional/browse_test.php +++ b/tests/functional/browse_test.php @@ -15,18 +15,21 @@ class phpbb_functional_browse_test extends phpbb_functional_test_case public function test_index() { $crawler = $this->request('GET', 'index.php'); + $this->assert_response_success(); $this->assertGreaterThan(0, $crawler->filter('.topiclist')->count()); } public function test_viewforum() { $crawler = $this->request('GET', 'viewforum.php?f=2'); + $this->assert_response_success(); $this->assertGreaterThan(0, $crawler->filter('.topiclist')->count()); } public function test_viewtopic() { $crawler = $this->request('GET', 'viewtopic.php?t=1'); + $this->assert_response_success(); $this->assertGreaterThan(0, $crawler->filter('.postbody')->count()); } } diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index e9409d9d3f..f28b321942 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -13,6 +13,14 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_case { protected $phpbb_extension_manager; + + static protected $fixtures = array( + 'foo/bar/config/routing.yml', + 'foo/bar/config/services.yml', + 'foo/bar/controller/controller.php', + 'foo/bar/styles/prosilver/template/foo_bar_body.html', + ); + /** * This should only be called once before the tests are run. * This is used to copy the fixtures to the phpBB install @@ -22,15 +30,11 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c global $phpbb_root_path; parent::setUpBeforeClass(); - // these directories need to be created before the files can be copied $directories = array( - $phpbb_root_path . 'ext/error/class/', - $phpbb_root_path . 'ext/error/classtype/', - $phpbb_root_path . 'ext/error/disabled/', $phpbb_root_path . 'ext/foo/bar/', - $phpbb_root_path . 'ext/foo/bar/styles/prosilver/template/', - $phpbb_root_path . 'ext/foobar/', - $phpbb_root_path . 'ext/foobar/styles/prosilver/template/', + $phpbb_root_path . 'ext/foo/bar/config/', + $phpbb_root_path . 'ext/foo/bar/controller/', + $phpbb_root_path . 'ext/foo/bar/styles/prosilver/template', ); foreach ($directories as $dir) @@ -41,28 +45,34 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c } } - $fixtures = array( - 'error/class/controller.php', - 'error/class/ext.php', - 'error/classtype/controller.php', - 'error/classtype/ext.php', - 'error/disabled/controller.php', - 'error/disabled/ext.php', - 'foo/bar/controller.php', - 'foo/bar/ext.php', - 'foo/bar/styles/prosilver/template/foobar_body.html', - 'foobar/controller.php', - 'foobar/ext.php', - 'foobar/styles/prosilver/template/foobar_body.html', - ); + foreach (self::$fixtures as $fixture) + { + copy( + "tests/functional/fixtures/ext/$fixture", + "{$phpbb_root_path}ext/$fixture"); + } + } - foreach ($fixtures as $fixture) + /** + * This should only be called once after the tests are run. + * This is used to remove the fixtures from the phpBB install + */ + static public function tearDownAfterClass() + { + global $phpbb_root_path; + + foreach (self::$fixtures as $fixture) { - if (!copy("tests/functional/fixtures/ext/$fixture", "{$phpbb_root_path}ext/$fixture")) - { - echo 'Could not copy file ' . $fixture; - } + unlink("{$phpbb_root_path}ext/$fixture"); } + + rmdir("{$phpbb_root_path}ext/foo/bar/config"); + rmdir("{$phpbb_root_path}ext/foo/bar/controller"); + rmdir("{$phpbb_root_path}ext/foo/bar/styles/prosilver/template"); + rmdir("{$phpbb_root_path}ext/foo/bar/styles/prosilver"); + rmdir("{$phpbb_root_path}ext/foo/bar/styles"); + rmdir("{$phpbb_root_path}ext/foo/bar"); + rmdir("{$phpbb_root_path}ext/foo"); } public function setUp() @@ -75,70 +85,67 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c } /** - * Check an extension at ./ext/foobar/ which should have the class - * phpbb_ext_foobar_controller - */ - public function test_foobar() - { - $this->phpbb_extension_manager->enable('foobar'); - $crawler = $this->request('GET', 'index.php?ext=foobar'); - $this->assertContains("This is for testing purposes.", $crawler->filter('#page-body')->text()); - $this->phpbb_extension_manager->purge('foobar'); - } - - /** - * Check an extension at ./ext/foo/bar/ which should have the class - * phpbb_ext_foo_bar_controller + * Check a controller for extension foo/bar. */ public function test_foo_bar() { $this->phpbb_extension_manager->enable('foo/bar'); - $crawler = $this->request('GET', 'index.php?ext=foo/bar'); - $this->assertContains("This is for testing purposes.", $crawler->filter('#page-body')->text()); + $crawler = $this->request('GET', 'app.php?controller=foo/bar'); + $this->assert_response_success(); + $this->assertContains("foo/bar controller handle() method", $crawler->filter('body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); } /** - * Check the error produced by extension at ./ext/error/class which has class - * phpbb_ext_foobar_controller + * Check the output of a controller using the template system */ - public function test_error_class_name() + public function test_controller_with_template() { - $this->phpbb_extension_manager->enable('error/class'); - $crawler = $this->request('GET', 'index.php?ext=error/class'); - $this->assertContains("The extension error/class is missing a controller class and cannot be accessed through the front-end.", $crawler->filter('#message')->text()); - $this->phpbb_extension_manager->purge('error/class'); + $this->phpbb_extension_manager->enable('foo/bar'); + $crawler = $this->request('GET', 'app.php?controller=foo/template'); + $this->assert_response_success(); + $this->assertContains("I am a variable", $crawler->filter('#content')->text()); + $this->phpbb_extension_manager->purge('foo/bar'); } /** - * Check the error produced by extension at ./ext/error/classtype which has class - * phpbb_ext_error_classtype_controller but does not implement phpbb_extension_controller_interface + * Check the error produced by calling a controller without a required + * argument. */ - public function test_error_class_type() + public function test_missing_argument() { - $this->phpbb_extension_manager->enable('error/classtype'); - $crawler = $this->request('GET', 'index.php?ext=error/classtype'); - $this->assertContains("The extension controller class phpbb_ext_error_classtype_controller is not an instance of the phpbb_extension_controller_interface.", $crawler->filter('#message')->text()); - $this->phpbb_extension_manager->purge('error/classtype'); + $this->phpbb_extension_manager->enable('foo/bar'); + $crawler = $this->request('GET', 'app.php?controller=foo/baz'); + $this->assertEquals(500, $this->client->getResponse()->getStatus()); + $this->assertContains('Missing value for argument #1: test in class phpbb_ext_foo_bar_controller:baz', $crawler->filter('body')->text()); + $this->phpbb_extension_manager->purge('foo/bar'); } /** - * Check the error produced by extension at ./ext/error/disabled that is (obviously) - * a disabled extension + * Check the status code resulting from an exception thrown by a controller */ - public function test_error_ext_disabled() + public function test_exception_should_result_in_500_status_code() { - $crawler = $this->request('GET', 'index.php?ext=error/disabled'); - $this->assertContains("The extension error/disabled is not enabled", $crawler->filter('#message')->text()); + $this->phpbb_extension_manager->enable('foo/bar'); + $crawler = $this->request('GET', 'app.php?controller=foo/exception'); + $this->assertEquals(500, $this->client->getResponse()->getStatus()); + $this->assertContains('Exception thrown from foo/exception route', $crawler->filter('body')->text()); + $this->phpbb_extension_manager->purge('foo/bar'); } /** - * Check the error produced by extension at ./ext/error/404 that is (obviously) - * not existant + * Check the error produced by extension at ./ext/does/not/exist. + * + * If an extension is disabled, its routes are not loaded. Because we + * are not looking for a controller based on a specified extension, + * we don't know the difference between a route in a disabled + * extension and a route that is not defined anyway; it is the same + * error message. */ - public function test_error_ext_missing() + public function test_error_ext_disabled_or_404() { - $crawler = $this->request('GET', 'index.php?ext=error/404'); - $this->assertContains("The extension error/404 does not exist.", $crawler->filter('#message')->text()); + $crawler = $this->request('GET', 'app.php?controller=does/not/exist'); + $this->assertEquals(404, $this->client->getResponse()->getStatus()); + $this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text()); } } diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index f7267fa659..99afcfdc3d 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -64,6 +64,9 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case public function test_valid_file() { $crawler = $this->upload_file('valid.jpg', 'image/jpeg'); + $this->assert_response_success(); + // ensure there was no error message rendered + $this->assertNotContains('<h2>' . $this->lang('INFORMATION') . '</h2>', $this->client->getResponse()->getContent()); $this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->eq(1)->text()); } } diff --git a/tests/functional/fixtures/ext/error/class/controller.php b/tests/functional/fixtures/ext/error/class/controller.php deleted file mode 100644 index 74bbbee540..0000000000 --- a/tests/functional/fixtures/ext/error/class/controller.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php - -class phpbb_ext_foobar_controller extends phpbb_extension_controller -{ - public function handle() - { - $this->template->set_filenames(array( - 'body' => 'index_body.html' - )); - - page_header('Test extension'); - page_footer(); - } -} diff --git a/tests/functional/fixtures/ext/error/class/ext.php b/tests/functional/fixtures/ext/error/class/ext.php deleted file mode 100644 index f97ad2b838..0000000000 --- a/tests/functional/fixtures/ext/error/class/ext.php +++ /dev/null @@ -1,6 +0,0 @@ -<?php - -class phpbb_ext_error_class_ext extends phpbb_extension_base -{ - -} diff --git a/tests/functional/fixtures/ext/error/classtype/controller.php b/tests/functional/fixtures/ext/error/classtype/controller.php deleted file mode 100644 index 55ac651bdf..0000000000 --- a/tests/functional/fixtures/ext/error/classtype/controller.php +++ /dev/null @@ -1,15 +0,0 @@ -<?php - -class phpbb_ext_error_classtype_controller -{ - public function handle() - { - global $template; - $template->set_filenames(array( - 'body' => 'index_body.html' - )); - - page_header('Test extension'); - page_footer(); - } -} diff --git a/tests/functional/fixtures/ext/error/classtype/ext.php b/tests/functional/fixtures/ext/error/classtype/ext.php deleted file mode 100644 index 35b1cd15a2..0000000000 --- a/tests/functional/fixtures/ext/error/classtype/ext.php +++ /dev/null @@ -1,6 +0,0 @@ -<?php - -class phpbb_ext_error_classtype_ext extends phpbb_extension_base -{ - -} diff --git a/tests/functional/fixtures/ext/error/disabled/controller.php b/tests/functional/fixtures/ext/error/disabled/controller.php deleted file mode 100644 index 57b913f377..0000000000 --- a/tests/functional/fixtures/ext/error/disabled/controller.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php - -class phpbb_ext_error_disabled_controller extends phpbb_extension_controller -{ - public function handle() - { - $this->template->set_filenames(array( - 'body' => 'index_body.html' - )); - - page_header('Test extension'); - page_footer(); - } -} diff --git a/tests/functional/fixtures/ext/error/disabled/ext.php b/tests/functional/fixtures/ext/error/disabled/ext.php deleted file mode 100644 index aec8051848..0000000000 --- a/tests/functional/fixtures/ext/error/disabled/ext.php +++ /dev/null @@ -1,6 +0,0 @@ -<?php - -class phpbb_ext_error_disabled_ext extends phpbb_extension_base -{ - -} diff --git a/tests/functional/fixtures/ext/foo/bar/config/routing.yml b/tests/functional/fixtures/ext/foo/bar/config/routing.yml new file mode 100644 index 0000000000..09a30a8c67 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/config/routing.yml @@ -0,0 +1,15 @@ +foo_bar_controller: + pattern: /foo/bar + defaults: { _controller: foo_bar.controller:handle } + +foo_baz_controller: + pattern: /foo/baz + defaults: { _controller: foo_bar.controller:baz } + +foo_template_controller: + pattern: /foo/template + defaults: { _controller: foo_bar.controller:template } + +foo_exception_controller: + pattern: /foo/exception + defaults: { _controller: foo_bar.controller:exception } diff --git a/tests/functional/fixtures/ext/foo/bar/config/services.yml b/tests/functional/fixtures/ext/foo/bar/config/services.yml new file mode 100644 index 0000000000..33ced55af9 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/config/services.yml @@ -0,0 +1,6 @@ +services: + foo_bar.controller: + class: phpbb_ext_foo_bar_controller + arguments: + - @controller.helper + - @template diff --git a/tests/functional/fixtures/ext/foo/bar/controller.php b/tests/functional/fixtures/ext/foo/bar/controller.php deleted file mode 100644 index 3375e317b3..0000000000 --- a/tests/functional/fixtures/ext/foo/bar/controller.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php - -class phpbb_ext_foo_bar_controller extends phpbb_extension_controller -{ - public function handle() - { - $this->template->set_filenames(array( - 'body' => 'foobar_body.html' - )); - - page_header('Test extension'); - page_footer(); - } -} diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php new file mode 100644 index 0000000000..5a91b5f681 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/controller/controller.php @@ -0,0 +1,35 @@ +<?php +use Symfony\Component\HttpFoundation\Response; + +class phpbb_ext_foo_bar_controller +{ + protected $template; + + public function __construct(phpbb_controller_helper $helper, phpbb_template $template) + { + $this->template = $template; + $this->helper = $helper; + } + + public function handle() + { + return new Response('foo/bar controller handle() method', 200); + } + + public function baz($test) + { + return new Response('Value of "test" URL argument is: ' . $test); + } + + public function template() + { + $this->template->assign_var('A_VARIABLE', 'I am a variable'); + + return $this->helper->render('foo_bar_body.html'); + } + + public function exception() + { + throw new phpbb_controller_exception('Exception thrown from foo/exception route'); + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/ext.php b/tests/functional/fixtures/ext/foo/bar/ext.php index 3a2068631e..74359d51ab 100644 --- a/tests/functional/fixtures/ext/foo/bar/ext.php +++ b/tests/functional/fixtures/ext/foo/bar/ext.php @@ -2,5 +2,5 @@ class phpbb_ext_foo_bar_ext extends phpbb_extension_base { - + } diff --git a/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar_body.html b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html index 4addf2666f..8fb6994d3d 100644 --- a/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar_body.html +++ b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html @@ -1,5 +1,3 @@ <!-- INCLUDE overall_header.html --> - -<div id="welcome">This is for testing purposes.</div> - +<div id="content">{A_VARIABLE}</div> <!-- INCLUDE overall_footer.html --> diff --git a/tests/functional/fixtures/ext/foobar/controller.php b/tests/functional/fixtures/ext/foobar/controller.php deleted file mode 100644 index ff35f12ee0..0000000000 --- a/tests/functional/fixtures/ext/foobar/controller.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php - -class phpbb_ext_foobar_controller extends phpbb_extension_controller -{ - public function handle() - { - $this->template->set_filenames(array( - 'body' => 'foobar_body.html' - )); - - page_header('Test extension'); - page_footer(); - } -} diff --git a/tests/functional/fixtures/ext/foobar/ext.php b/tests/functional/fixtures/ext/foobar/ext.php deleted file mode 100644 index 7cf443d369..0000000000 --- a/tests/functional/fixtures/ext/foobar/ext.php +++ /dev/null @@ -1,6 +0,0 @@ -<?php - -class phpbb_ext_foobar_ext extends phpbb_extension_base -{ - -} diff --git a/tests/functional/fixtures/ext/foobar/styles/prosilver/template/foobar_body.html b/tests/functional/fixtures/ext/foobar/styles/prosilver/template/foobar_body.html deleted file mode 100644 index 4addf2666f..0000000000 --- a/tests/functional/fixtures/ext/foobar/styles/prosilver/template/foobar_body.html +++ /dev/null @@ -1,5 +0,0 @@ -<!-- INCLUDE overall_header.html --> - -<div id="welcome">This is for testing purposes.</div> - -<!-- INCLUDE overall_footer.html --> diff --git a/tests/functions/get_formatted_filesize_test.php b/tests/functions/get_formatted_filesize_test.php new file mode 100644 index 0000000000..96ea2be132 --- /dev/null +++ b/tests/functions/get_formatted_filesize_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_get_formatted_filesize_test extends phpbb_test_case +{ + public function get_formatted_filesize_test_data() + { + return array( + // exact powers of 2 + array(1, '1 BYTES'), + array(1024, '1 KIB'), + array(1048576, '1 MIB'), + array(1073741824, '1 GIB'), + array(1099511627776, '1 TIB'), + + // exact powers of 10 + array(1000, '1000 BYTES'), + array(1000000, '976.56 KIB'), + array(1000000000, '953.67 MIB'), + array(1000000000000, '931.32 GIB'), + array(100000000000000, '90.95 TIB'), + + array(0, '0 BYTES'), + array(2, '2 BYTES'), + + array(1023, '1023 BYTES'), + array(1025, '1 KIB'), + array(1048575, '1024 KIB'), + + // String values + // exact powers of 2 + array('1', '1 BYTES'), + array('1024', '1 KIB'), + array('1048576', '1 MIB'), + array('1073741824', '1 GIB'), + array('1099511627776', '1 TIB'), + + // exact powers of 10 + array('1000', '1000 BYTES'), + array('1000000', '976.56 KIB'), + array('1000000000', '953.67 MIB'), + array('1000000000000', '931.32 GIB'), + array('100000000000000', '90.95 TIB'), + + array('0', '0 BYTES'), + array('2', '2 BYTES'), + + array('1023', '1023 BYTES'), + array('1025', '1 KIB'), + array('1048575', '1024 KIB'), + ); + } + + /** + * @dataProvider get_formatted_filesize_test_data + */ + public function test_get_formatted_filesize($input, $expected) + { + $output = get_formatted_filesize($input); + + $this->assertEquals($expected, $output); + } +} diff --git a/tests/lint_test.php b/tests/lint_test.php new file mode 100644 index 0000000000..905067072d --- /dev/null +++ b/tests/lint_test.php @@ -0,0 +1,74 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_lint_test extends phpbb_test_case +{ + static protected $exclude; + + static public function setUpBeforeClass() + { + $output = array(); + $status = 1; + exec('(php -v) 2>&1', $output, $status); + if ($status) + { + $output = implode("\n", $output); + self::markTestSkipped("php is not in PATH or broken: $output"); + } + + self::$exclude = array( + // PHP Fatal error: Cannot declare class Container because the name is already in use in /var/www/projects/phpbb3/tests/../phpBB/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php on line 20 + // https://gist.github.com/e003913ffd493da63cbc + dirname(__FILE__) . '/../phpBB/vendor', + ); + } + + public function test_lint() + { + if (version_compare(PHP_VERSION, '5.3.0', '<')) + { + $this->markTestSkipped('phpBB uses PHP 5.3 syntax in some files, linting on PHP < 5.3 will fail'); + } + + $root = dirname(__FILE__) . '/..'; + $this->check($root); + } + + protected function check($root) + { + $dh = opendir($root); + while (($filename = readdir($dh)) !== false) + { + if ($filename == '.' || $filename == '..' || $filename == 'git') + { + continue; + } + $path = $root . '/' . $filename; + // skip symlinks to avoid infinite loops + if (is_link($path)) + { + continue; + } + if (is_dir($path) && !in_array($path, self::$exclude)) + { + $this->check($path); + } + else if (substr($filename, strlen($filename)-4) == '.php') + { + // assume php binary is called php and it is in PATH + $cmd = '(php -l ' . escapeshellarg($path) . ') 2>&1'; + $output = array(); + $status = 1; + exec($cmd, $output, $status); + $output = implode("\n", $output); + $this->assertEquals(0, $status, "php -l failed for $path:\n$output"); + } + } + } +} diff --git a/tests/lock/flock_test.php b/tests/lock/flock_test.php new file mode 100644 index 0000000000..1edc96b3a4 --- /dev/null +++ b/tests/lock/flock_test.php @@ -0,0 +1,109 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_lock_flock_test extends phpbb_test_case +{ + public function test_lock() + { + $path = __DIR__ . '/../tmp/precious'; + + $lock = new phpbb_lock_flock($path); + $ok = $lock->acquire(); + $this->assertTrue($ok); + $lock->release(); + } + + public function test_consecutive_locking() + { + $path = __DIR__ . '/../tmp/precious'; + + $lock = new phpbb_lock_flock($path); + $ok = $lock->acquire(); + $this->assertTrue($ok); + $lock->release(); + + $ok = $lock->acquire(); + $this->assertTrue($ok); + $lock->release(); + + $ok = $lock->acquire(); + $this->assertTrue($ok); + $lock->release(); + } + + /* This hangs the process. + public function test_concurrent_locking_fail() + { + $path = __DIR__ . '/../tmp/precious'; + + $lock1 = new phpbb_lock_flock($path); + $ok = $lock1->acquire(); + $this->assertTrue($ok); + + $lock2 = new phpbb_lock_flock($path); + $ok = $lock2->acquire(); + $this->assertFalse($ok); + + $lock->release(); + $ok = $lock2->acquire(); + $this->assertTrue($ok); + } + */ + + public function test_concurrent_locking() + { + if (!function_exists('pcntl_fork')) + { + $this->markTestSkipped('pcntl extension and pcntl_fork are required for this test'); + } + + $path = __DIR__ . '/../tmp/precious'; + + $pid = pcntl_fork(); + if ($pid) + { + // parent + // wait 0.5 s, acquire the lock, note how long it took + sleep(1); + + $lock = new phpbb_lock_flock($path); + $start = time(); + $ok = $lock->acquire(); + $delta = time() - $start; + $this->assertTrue($ok); + $this->assertGreaterThan(0.5, $delta, 'First lock acquired too soon'); + + $lock->release(); + + // acquire again, this should be instantaneous + $start = time(); + $ok = $lock->acquire(); + $delta = time() - $start; + $this->assertTrue($ok); + $this->assertLessThan(0.1, $delta, 'Second lock not acquired instantaneously'); + + // reap the child + $status = null; + pcntl_waitpid($pid, $status); + } + else + { + // child + // immediately acquire the lock and sleep for 2 s + $lock = new phpbb_lock_flock($path); + $ok = $lock->acquire(); + $this->assertTrue($ok); + sleep(2); + $lock->release(); + + // and go away silently + pcntl_exec('/usr/bin/env', array('true')); + } + } +} diff --git a/tests/mock/cache.php b/tests/mock/cache.php index b64c92ea89..bc18ca066b 100644 --- a/tests/mock/cache.php +++ b/tests/mock/cache.php @@ -123,6 +123,7 @@ class phpbb_mock_cache implements phpbb_cache_driver_interface } public function sql_save($query, $query_result, $ttl) { + return $query_result; } public function sql_exists($query_id) { diff --git a/tests/search/common_test_case.php b/tests/search/common_test_case.php new file mode 100644 index 0000000000..dd04f7048c --- /dev/null +++ b/tests/search/common_test_case.php @@ -0,0 +1,106 @@ +<?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__) . '/../test_framework/phpbb_search_test_case.php'; + +abstract class phpbb_search_common_test_case extends phpbb_search_test_case +{ + public function keywords() + { + return array( + // keywords + // terms + // ok + // split words + // common words + array( + 'fooo', + 'all', + true, + array('fooo'), + array(), + ), + array( + 'fooo baar', + 'all', + true, + array('fooo', 'baar'), + array(), + ), + // leading, trailing and multiple spaces + array( + ' fooo baar ', + 'all', + true, + array('fooo', 'baar'), + array(), + ), + // words too short + array( + 'f', + 'all', + false, + null, + // short words count as "common" words + array('f'), + ), + array( + 'f o o', + 'all', + false, + null, + array('f', 'o', 'o'), + ), + array( + 'f -o -o', + 'all', + false, + null, + array('f', '-o', '-o'), + ), + array( + 'fooo -baar', + 'all', + true, + array('-baar', 'fooo'), + array(), + ), + // all negative + array( + '-fooo', + 'all', + true, + array('-fooo'), + array(), + ), + array( + '-fooo -baar', + 'all', + true, + array('-fooo', '-baar'), + array(), + ), + ); + } + + /** + * @dataProvider keywords + */ + public function test_split_keywords($keywords, $terms, $ok, $split_words, $common) + { + $rv = $this->search->split_keywords($keywords, $terms); + $this->assertEquals($ok, $rv); + if ($ok) + { + // only check criteria if the search is going to be performed + $this->assert_array_content_equals($split_words, $this->search->get_split_words()); + } + $this->assert_array_content_equals($common, $this->search->get_common_words()); + } +} diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php new file mode 100644 index 0000000000..3ba3915714 --- /dev/null +++ b/tests/search/mysql_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__) . '/common_test_case.php'; + +class phpbb_search_mysql_test extends phpbb_search_common_test_case +{ + protected $db; + protected $search; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/../fixtures/empty.xml'); + } + + protected function setUp() + { + global $phpbb_root_path, $phpEx, $config, $user, $cache; + + parent::setUp(); + + // dbal uses cache + $cache = new phpbb_cache_service(new phpbb_cache_driver_null); + + // set config values + $config['fulltext_mysql_min_word_len'] = 4; + $config['fulltext_mysql_max_word_len'] = 254; + + $this->db = $this->new_dbal(); + $error = null; + $class = self::get_search_wrapper('phpbb_search_fulltext_mysql'); + $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); + } +} diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 66972079cf..eeee3a44f3 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -7,24 +7,9 @@ * */ -function phpbb_search_wrapper($class) -{ - $wrapped = $class . '_wrapper'; - if (!class_exists($wrapped)) - { - $code = " -class $wrapped extends $class -{ - public function get_must_contain_ids() { return \$this->must_contain_ids; } - public function get_must_not_contain_ids() { return \$this->must_not_contain_ids; } -} - "; - eval($code); - } - return $wrapped; -} +require_once dirname(__FILE__) . '/../test_framework/phpbb_search_test_case.php'; -class phpbb_search_native_test extends phpbb_database_test_case +class phpbb_search_native_test extends phpbb_search_test_case { protected $db; protected $search; @@ -41,19 +26,14 @@ class phpbb_search_native_test extends phpbb_database_test_case parent::setUp(); // dbal uses cache - $cache = new phpbb_cache_driver_null; + $cache = new phpbb_cache_service(new phpbb_cache_driver_null); $this->db = $this->new_dbal(); $error = null; - $class = phpbb_search_wrapper('phpbb_search_fulltext_native'); + $class = self::get_search_wrapper('phpbb_search_fulltext_native'); $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } - protected function tearDown() - { - parent::tearDown(); - } - public function keywords() { return array( @@ -107,6 +87,14 @@ class phpbb_search_native_test extends phpbb_database_test_case array('f', 'o', 'o'), ), array( + 'f -o -o', + 'all', + false, + null, + null, + array('f', 'o', 'o'), + ), + array( 'foo -bar', 'all', true, @@ -167,20 +155,4 @@ class phpbb_search_native_test extends phpbb_database_test_case } $this->assert_array_content_equals($common, $this->search->get_common_words()); } - - public function assert_array_content_equals($one, $two) - { - // http://stackoverflow.com/questions/3838288/phpunit-assert-two-arrays-are-equal-but-order-of-elements-not-important - // but one array_diff is not enough! - if (sizeof(array_diff($one, $two)) || sizeof(array_diff($two, $one))) - { - // get a nice error message - $this->assertEquals($one, $two); - } - else - { - // increase assertion count - $this->assertTrue(true); - } - } } diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php new file mode 100644 index 0000000000..9c77e0c09e --- /dev/null +++ b/tests/search/postgres_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__) . '/common_test_case.php'; + +class phpbb_search_postgres_test extends phpbb_search_common_test_case +{ + protected $db; + protected $search; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/../fixtures/empty.xml'); + } + + protected function setUp() + { + global $phpbb_root_path, $phpEx, $config, $user, $cache; + + parent::setUp(); + + // dbal uses cache + $cache = new phpbb_cache_service(new phpbb_cache_driver_null); + + // set config values + $config['fulltext_postgres_min_word_len'] = 4; + $config['fulltext_postgres_max_word_len'] = 254; + + $this->db = $this->new_dbal(); + $error = null; + $class = self::get_search_wrapper('phpbb_search_fulltext_postgres'); + $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); + } +} diff --git a/tests/template/template_locate_test.php b/tests/template/template_locate_test.php index be9ae06809..851dcae8ea 100644 --- a/tests/template/template_locate_test.php +++ b/tests/template/template_locate_test.php @@ -62,7 +62,7 @@ class phpbb_template_template_locate_test extends phpbb_template_template_test_c $this->setup_engine(); // Locate template - $result = $this->template->locate($files, $return_default, $return_full_path); + $result = $this->style_resource_locator->get_first_template_location($files, $return_default, $return_full_path); $this->assertSame($expected, $result); } } diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 75a3c0944b..b5076b92e9 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -13,6 +13,8 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test protected $test_case_helpers; + protected $fixture_xml_data; + public function __construct($name = NULL, array $data = array(), $dataName = '') { parent::__construct($name, $data, $dataName); @@ -28,6 +30,20 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test ); } + protected function setUp() + { + parent::setUp(); + + // Resynchronise tables if a fixture was loaded + if (isset($this->fixture_xml_data)) + { + $config = $this->get_database_config(); + $manager = $this->create_connection_manager($config); + $manager->connect(); + $manager->post_setup_synchronisation($this->fixture_xml_data); + } + } + public function createXMLDataSet($path) { $db_config = $this->get_database_config(); @@ -47,7 +63,9 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $path = $meta_data['uri']; } - return parent::createXMLDataSet($path); + $this->fixture_xml_data = parent::createXMLDataSet($path); + + return $this->fixture_xml_data; } public function get_test_case_helpers() @@ -141,4 +159,20 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test { return $matches[1] . strtoupper($matches[2]) . $matches[3]; } + + public function assert_array_content_equals($one, $two) + { + // http://stackoverflow.com/questions/3838288/phpunit-assert-two-arrays-are-equal-but-order-of-elements-not-important + // but one array_diff is not enough! + if (sizeof(array_diff($one, $two)) || sizeof(array_diff($two, $one))) + { + // get a nice error message + $this->assertEquals($one, $two); + } + else + { + // increase assertion count + $this->assertTrue(true); + } + } } diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 25e0972f42..d7c2804aa7 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -166,12 +166,6 @@ class phpbb_database_test_connection_manager switch ($this->config['dbms']) { case 'sqlite': - if (file_exists($this->config['dbhost'])) - { - unlink($this->config['dbhost']); - } - break; - case 'firebird': $this->connect(); // Drop all of the tables @@ -432,4 +426,111 @@ class phpbb_database_test_connection_manager $this->pdo->exec($query); } } + + /** + * Performs synchronisations on the database after a fixture has been loaded + * + * @param PHPUnit_Extensions_Database_DataSet_XmlDataSet $xml_data_set Information about the tables contained within the loaded fixture + * + * @return null + */ + public function post_setup_synchronisation($xml_data_set) + { + $this->ensure_connected(__METHOD__); + $queries = array(); + + // Get escaped versions of the table names used in the fixture + $table_names = array_map(array($this->pdo, 'PDO::quote'), $xml_data_set->getTableNames()); + + switch ($this->config['dbms']) + { + case '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 + JOIN USER_DEPENDENCIES d ON (d.name = t.trigger_name) + JOIN USER_TRIGGER_COLS tc ON (tc.trigger_name = t.trigger_name) + JOIN USER_SEQUENCES s ON (s.sequence_name = d.referenced_name) + WHERE d.referenced_type = 'SEQUENCE' + AND d.type = 'TRIGGER' + AND t.table_name IN (" . implode(', ', array_map('strtoupper', $table_names)) . ')'; + + $result = $this->pdo->query($sql); + + while ($row = $result->fetch(PDO::FETCH_ASSOC)) + { + // Get the current max value of the table + $sql = "SELECT MAX({$row['COLUMN_NAME']}) AS max FROM {$row['TABLE_NAME']}"; + $max_result = $this->pdo->query($sql); + $max_row = $max_result->fetch(PDO::FETCH_ASSOC); + + if (!$max_row) + { + continue; + } + + $max_val = (int) $max_row['MAX']; + $max_val++; + + /** + * This is not the "proper" way, but the proper way does not allow you to completely reset + * tables with no rows since you have to select the next value to make the change go into effect. + * You would have to go past the minimum value to set it correctly, but that's illegal. + * Since we have no objects attached to our sequencers (triggers aren't attached), this works fine. + */ + $queries[] = 'DROP SEQUENCE ' . $row['SEQUENCE_NAME']; + $queries[] = "CREATE SEQUENCE {$row['SEQUENCE_NAME']} + MINVALUE {$row['MIN_VALUE']} + INCREMENT BY {$row['INCREMENT_BY']} + START WITH $max_val"; + } + break; + + case '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) . ") + AND strpos(column_default, '_seq''::regclass') > 0"; + $result = $this->pdo->query($sql); + + $setval_queries = array(); + while ($row = $result->fetch(PDO::FETCH_ASSOC)) + { + // Get the columns used in the fixture for this table + $column_names = $xml_data_set->getTableMetaData($row['table_name'])->getColumns(); + + // Skip sequences that weren't specified in the fixture + if (!in_array($row['column_name'], $column_names)) + { + continue; + } + + // Get the old value if it exists, or use 1 if it doesn't + $sql = "SELECT COALESCE((SELECT MAX({$row['column_name']}) + 1 FROM {$row['table_name']}), 1) AS val"; + $result_max = $this->pdo->query($sql); + $row_max = $result_max->fetch(PDO::FETCH_ASSOC); + + if ($row_max) + { + $seq_name = $this->pdo->quote($row['table_name'] . '_seq'); + $max_val = (int) $row_max['val']; + + // The last parameter is false so that the system doesn't increment it again + $setval_queries[] = "SETVAL($seq_name, $max_val, false)"; + } + } + + // Combine all of the SETVALs into one query + if (sizeof($setval_queries)) + { + $queries[] = 'SELECT ' . implode(', ', $setval_queries); + } + break; + } + + foreach ($queries as $query) + { + $this->pdo->exec($query); + } + } } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index eb2b497708..16e1ccaff9 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -332,15 +332,30 @@ class phpbb_functional_test_case extends phpbb_test_case return call_user_func_array('sprintf', $args); } - /** - * assertContains for language strings - * - * @param string $needle Search string - * @param string $haystack Search this - * @param string $message Optional failure message - */ - public function assertContainsLang($needle, $haystack, $message = null) - { - $this->assertContains(html_entity_decode($this->lang($needle), ENT_QUOTES), $haystack, $message); - } + /** + * assertContains for language strings + * + * @param string $needle Search string + * @param string $haystack Search this + * @param string $message Optional failure message + */ + public function assertContainsLang($needle, $haystack, $message = null) + { + $this->assertContains(html_entity_decode($this->lang($needle), ENT_QUOTES), $haystack, $message); + } + + /** + * Heuristic function to check that the response is success. + * + * When php decides to die with a fatal error, it still sends 200 OK + * status code. This assertion tries to catch that. + * + * @return null + */ + public function assert_response_success() + { + $this->assertEquals(200, $this->client->getResponse()->getStatus()); + $content = $this->client->getResponse()->getContent(); + $this->assertNotContains('Fatal error:', $content); + } } diff --git a/tests/test_framework/phpbb_search_test_case.php b/tests/test_framework/phpbb_search_test_case.php new file mode 100644 index 0000000000..418d352c17 --- /dev/null +++ b/tests/test_framework/phpbb_search_test_case.php @@ -0,0 +1,29 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +abstract class phpbb_search_test_case extends phpbb_database_test_case +{ + static protected function get_search_wrapper($class) + { + $wrapped = $class . '_wrapper'; + if (!class_exists($wrapped)) + { + $code = " +class $wrapped extends $class +{ + public function get_must_contain_ids() { return \$this->must_contain_ids; } + public function get_must_not_contain_ids() { return \$this->must_not_contain_ids; } + public function get_split_words() { return \$this->split_words; } +} + "; + eval($code); + } + return $wrapped; + } +} diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index d10645a732..fe15eded90 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -91,6 +91,15 @@ class phpbb_test_case_helpers { $config['phpbb_functional_url'] = $phpbb_functional_url; } + + if (isset($phpbb_redis_host)) + { + $config['redis_host'] = $phpbb_redis_host; + } + if (isset($phpbb_redis_port)) + { + $config['redis_port'] = $phpbb_redis_port; + } } if (isset($_SERVER['PHPBB_TEST_DBMS'])) @@ -113,6 +122,16 @@ class phpbb_test_case_helpers )); } + if (isset($_SERVER['PHPBB_TEST_REDIS_HOST'])) + { + $config['redis_host'] = $_SERVER['PHPBB_TEST_REDIS_HOST']; + } + + if (isset($_SERVER['PHPBB_TEST_REDIS_PORT'])) + { + $config['redis_port'] = $_SERVER['PHPBB_TEST_REDIS_PORT']; + } + return $config; } diff --git a/travis/phpunit-mysql-travis.xml b/travis/phpunit-mysql-travis.xml index e54b2bb77b..5366494c8b 100644 --- a/travis/phpunit-mysql-travis.xml +++ b/travis/phpunit-mysql-travis.xml @@ -9,6 +9,7 @@ stopOnFailure="false" syntaxCheck="true" strict="true" + verbose="true" bootstrap="../tests/bootstrap.php"> <testsuites> <testsuite name="phpBB Test Suite"> diff --git a/travis/phpunit-postgres-travis.xml b/travis/phpunit-postgres-travis.xml index 55ba996548..0383edd9d6 100644 --- a/travis/phpunit-postgres-travis.xml +++ b/travis/phpunit-postgres-travis.xml @@ -9,6 +9,7 @@ stopOnFailure="false" syntaxCheck="true" strict="true" + verbose="true" bootstrap="../tests/bootstrap.php"> <testsuites> <testsuite name="phpBB Test Suite"> |