From 421fc8d94db1b6a89518cbcc3f3141625eefff25 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Tue, 10 Apr 2012 11:25:06 +0100 Subject: [PATCH 001/113] [ticket/10776] Fixed errors in docs/README.html. PHPBB3-10776 --- phpBB/docs/README.html | 77 +++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/phpBB/docs/README.html b/phpBB/docs/README.html index aa60d7dd25..d54b9d920f 100644 --- a/phpBB/docs/README.html +++ b/phpBB/docs/README.html @@ -41,7 +41,7 @@ -

Thank you for downloading phpBB3. This README will guide through the basics of installation and operation of phpBB3. Please ensure you read this and the accompanying documentation fully before proceeding with the installation.

+

Thank you for downloading phpBB3. This README will guide you through the basics of installation and operation of phpBB3. Please ensure you read this and the accompanying documentation fully before proceeding with the installation.

Readme

@@ -62,12 +62,12 @@
  • Getting help with phpBB3
    1. Documentation
    2. -
    3. Community Forums
    4. +
    5. Community forums
    6. Internet Relay Chat
  • Status of this version
  • -
  • Reporting Bugs +
  • Reporting bugs
    1. Security related bugs
    @@ -91,11 +91,11 @@
    -

    Installation, update and conversion instructions can be found in the INSTALL document contained in this distribution. If you are intending to convert from a previous phpBB 2.0.x installation we highly recommend you backup any existing data before proceeding!

    +

    Installation, update and conversion instructions can be found in the INSTALL document in this directory. If you are intending on converting from a phpBB 2.0.x installation we highly recommend that you backup any existing data before proceeding!

    Users of phpBB3 Beta versions cannot directly update.

    -

    Please note that we won't support the following installation types:

    +

    Please note that we don't support the following installation types:

    • Updates from phpBB3 Beta versions to phpBB3 RC1 and higher
    • Conversions from phpBB 2.0.x to phpBB3 Beta versions
    • @@ -107,7 +107,7 @@
      • Updates from phpBB3 RC1 to the latest version
      • Conversions from phpBB 2.0.x to the latest version
      • -
      • New installations of phpBB3 - always only the latest released version
      • +
      • New installations of phpBB3 - only the latest released version
    @@ -134,33 +134,33 @@

    http://www.phpbb.com/downloads/

    -

    This is the official location for all supported language sets. If you download a package from a 3rd party site you do so with the understanding that we cannot offer support. So please, do not ask for help in these cases!

    +

    This is the official location for all supported language sets. If you download a package from a 3rd party site you do so with the understanding that we cannot offer support. Please do not ask for support if you download a language pack from a 3rd party site.

    -

    Installation of these packages is straightforward, simply download the required language pack and unarchive it into the languages/ folder. Please ensure you retain the directory structure when doing this! Once uploaded go to the Admin->System->Language Packs and install the now appeared new language pack. To install the style imageset you should download the imageset for your language and unarchive the file/s into the relevant imageset directory (styles/prosilver/imageset or styles/subsilver2/imageset), again you must retain the directory structure. Once installed the imageset will become immediately available.

    +

    Installation of these packages is straightforward; simply download the required language pack and unarchive it into the languages/ folder. Please ensure you retain the directory structure when doing this! Once uploaded go to the Admin->System->Language Packs and install the new language pack, which will have been automatically detected. To install the style imageset you should download the imageset for your language and unarchive the file/s into the relevant imageset directory (styles/prosilver/imageset or styles/subsilver2/imageset). Again, you must retain the directory structure. Once installed the imageset will immediately become available.

    If your language is not available please visit our forums where you will find a topic listing translations currently available or in preparation. This topic also gives you information should you wish to volunteer to translate a language not currently listed.

    2.ii. Styles

    -

    Although phpBB Group are rather proud of the included styles we realise that it may not be to everyones tastes. Therefore phpBB3 allows styles to be switched with relative ease. Firstly you need to locate and download a style you like. We maintain such a site at

    +

    Although phpBB Group are rather proud of the included styles we realise that it may not be to everyones tastes. Therefore phpBB3 allows other styles to be used with relative ease. First, you need to locate and download a style you like. We maintain such a site at

    http://www.phpbb.com/styles/

    -

    Please note that 3rd party styles downloaded for versions of phpBB2 will not work in phpBB3.

    +

    Please note that styles for phpBB2 will not work with phpBB3.

    -

    Once you have downloaded a style the usual next step is to unarchive (or upload the unarchived contents of) the package into your styles/ directory. You then need to visit Administration -> Styles, you should see the new style available, click install and it will become available for all your users.

    +

    Once you have downloaded a style, the next step is to unarchive (or upload the unarchived contents of) the package into your styles/ directory. You then need to visit Administration -> Styles. You should see the new style, click install and it will become available for all your users.

    -

    Please note that if you create your own style or modify existing ones, please remember to enable the "Recompile stale style components" setting within the Admin->General->Load Settings screen. This setting allows the cache to detect changes made to the style and automatically refresh it. If this setting is disabled, you will not see your changes taking effect.

    +

    Please note that if you create your own style or modify existing ones, you should enable the "Recompile stale style components" setting within the Admin->General->Load Settings screen. This setting allows the cache to detect changes made to the style and automatically refresh it. If this setting is disabled, you will not see your changes taking effect without manually refreshing the style components.

    2.iii. Modifications

    -

    Although not officially supported by phpBB Group, phpBB has a thriving modification scene. These third party modifications to the standard phpBB extend its capabilities still further and can be found at:

    +

    Although the modifications themselves are not officially supported by phpBB Group, phpBB has a thriving modification scene. These add features to phpBB, and can be found at:

    http://www.phpbb.com/mods/

    -

    Please remember that any bugs or other issues that occur after you have added any modification should NOT be reported to the bug tracker (see below). First remove the modification and see if the problem is resolved.

    +

    Please remember that any bugs or other issues that may occur as a result of installing a modification should NOT be reported to the bug tracker (see below). First remove the modification, and then see if that has fixed the problem.

    -

    Also remember that any modifications which modify the database in any way may render upgrading your forum to future versions more difficult unless we state otherwise. With all this said many users have and continue to utilise many of the mods already available with great success.

    +

    Also remember that any modifications which modify the database in any way may make upgrading your forum to future versions more difficult. However, many users have and continue to utilise many of the mods already available with great success.

    @@ -178,27 +178,27 @@
    -

    phpBB3 can seem a little daunting to new users in places, particularly with regard the permission system. The first thing you should do is check the FAQ which covers a few basic getting started questions. If you need additional help there are several places you should look.

    +

    phpBB3 can sometimes seem a little daunting to new users, particularly with regards to the permission system. The first thing you should do is check the FAQ, which covers a few basic getting started questions. If you need additional help there are several places you can find it.

    3.i. phpBB3 Documentation

    -

    A comprehensive documentation is now available online and can be accessed from the following location:

    +

    Comprehensive documentation is now available on the phpBB website:

    http://www.phpbb.com/support/documentation/3.0/

    -

    This covers everything from installation through setting permissions and managing users.

    +

    This covers everything from installation to setting permissions and managing users.

    3.ii. Community Forums

    -

    phpBB Group maintains a thriving community where a number of people have generously decided to donate their time to help support users. This site can be found at:

    +

    phpBB Group maintains a thriving community where a number of people generously donate their time to help support users. This site can be found at:

    -

    http://www.phpbb.com/

    +

    http://www.phpbb.com/community/

    -

    If you do seek help via our forums please be sure to do a Search before posting. This may well save both you and us time and allow the developer, moderator and support groups to spend more time responding to people with unknown issues and problems. Please also remember that phpBB is an entirely volunteer effort, no one receives any compensation for the time they give, this includes moderators as well as developers. So please be respectful and mindful when awaiting responses.

    +

    If you do seek help via our forums please be sure to do a search before posting to make sure; if someone has experienced the issue before, then you may find that your question has already been answered. Please remember that phpBB is entirely staffed by volunteers, no one receives any compensation for the time they give, including moderators as well as developers; please be respectful and mindful when awaiting responses and receiving support.

    3.iii Internet Relay Chat

    -

    Another place you may find help is our IRC channel. This operates on the Freenode IRC network, irc.freenode.net and the channel is #phpbb and can be accessed by any good IRC client such as mIRC, XChat, etc. Again, please do not abuse this service and be respectful of other users.

    +

    Another place you can find help is our IRC channel, which you can find on the Freenode IRC network, irc.freenode.net in #phpbb. It can be accessed by any IRC client such as mIRC, XChat, etc. Again, please do not abuse this service and be respectful of other users.

    @@ -216,13 +216,13 @@
    -

    This is the third stable release of phpBB. The 3.0.x line is essentially feature frozen, with only point releases seeing fixes for bugs and security issues, though feature alterations and minor feature additions may be done if deemed absolutely required. Our next major release will be phpBB 3.2 and the planning phase has begun (the unstable development version is 3.1). Please do not post questions asking when 3.2 will be available, no release date has been set.

    +

    This is the third stable release of phpBB. The 3.0.x line is essentially feature frozen, with releases only containing fixes for bugs and security issues, though feature alterations and minor feature additions may be done if deemed absolutely required. Our next major release will be phpBB 3.1, which is currently under development. Please do not post questions asking when any future releases will be released; they will be released when they are finished.

    -

    For those interested in the development of phpBB should keep an eye on the community forums to see how things are progressing:

    +

    Those interested in the development of phpBB should keep an eye on the forums on the development site, Area51, to see how things are progressing and to help out if you wish:

    http://area51.phpbb.com/phpBB/

    -

    Please note that this forum should NOT be used to obtain support for or ask questions about phpBB 2.0.x or phpBB 3.0.x, the main community forums are the place for this. Any such posts will be locked and go unanswered.

    +

    Please note that these forums should NOT be used to obtain support, as the main community forums are the place for this. Any such posts will be locked and go unanswered.

    @@ -240,20 +240,19 @@
    -

    The phpBB Group uses a bug tracking system to store, list and manage all reported bugs, it can be found at the location listed below. Please DO NOT post bug reports to our forums, they will be locked. In addition please DO NOT use the bug tracker for support requests. Posting such a request will only see you directed to the support forums (while taking time away from working on real bugs).

    +

    The phpBB Group uses a bug tracking system to manage all reported bugs, which can be found at the location listed below. Please DO NOT post bug reports to our forums, they will be locked. In addition please DO NOT use the bug tracker for support requests. Posting such a request will only see you directed to the support forums (while taking time away from working on real bugs).

    http://tracker.phpbb.com/

    While we very much appreciate receiving bug reports (the more reports the more stable phpBB will be) we ask you carry out a few steps before adding new entries:

      -
    • Firstly determine if your bug is reproduceable, how to determine this depends on the bug in question. Only if the bug is reproduceable it is likely to be a problem with phpBB3 (or in some way connected). If something cannot be reproduced it may turn out to have been your hosting provider working on something, a user doing something silly, etc. Bug reports for non-reproduceable events can slow down our attempts to fix real, reproduceable issues

    • -
    • Next please read or search through the existing bug reports to see if your bug (or one very similar to it) is already listed. If it is please add to that existing bug rather than creating a new duplicate entry (all this does is slow us down).

    • -
    • Check the forums (use search!) to see if people have discussed anything that sounds similar to what you are seeing. However, as noted above please DO NOT post your particular bug to the forum unless it's non-reproduceable or you are sure it's related to something you have done rather phpBB3

    • -
    • If no existing bug exists then please feel free to add it
    • +
    • First determine if your bug is reproducible. How to determine this depends on the bug in question. If the bug is reproduceable it is likely to be a problem with phpBB3 (or in some way connected). If it cannot, then it is most likely not a bug in phpBB.

    • +
    • Next please read or search through the existing bug reports to see whether we already know about the bug you found. If there is already a ticket, then please add to that existing bug rather than creating a new duplicate entry (all this does is slow us down).

    • +
    • If no existing bug exists then please add it
    -

    If you do post a new bug (i.e. one that isn't already listed in the bug tracker) firstly make sure you have logged in (your username and password are the same as for the community forums) then please include the following details:

    +

    If you do post a new bug, make sure you are logged in (your username and password are the same as for the community forums) then please include the following details in your bug report:

    • Your server type/version, e.g. Apache 1.3.28, IIS 4, Sambar, etc.
    • @@ -263,9 +262,9 @@

      The relevant database type/version is listed within the administration control panel

      -

      Please also be as detailed as you can in your report, if possible list the steps required to duplicate the problem. If you have a patch that fixes the issue, please attach it to the ticket or submit a pull request on GitHub.

      +

      Please be as detailed as you can in your report, and if possible, list the steps required to duplicate the problem. If you have a patch that fixes the issue, please attach it to the ticket or submit a pull request to our repository on GitHub.

      -

      Once a bug has been submitted you will be emailed any follow up comments added to it. Please if you are requested to supply additional information, do so! It is frustrating for us to receive bug reports, ask for additional information but get nothing. In these cases we have a policy of closing the bug, which may leave a very real problem in place. Obviously we would rather not have this situation arise.

      +

      Once a bug has been submitted you will be emailed any follow up comments added to it. If you are requested to supply additional information, please do so! It is frustrating for us to receive bug reports, ask for additional information but get nothing. If we cannot replicate the bug we may close the ticket, which could leave the bug in phpBB. Obviously we would rather not have this situation arise.

      5.i. Security related bugs

      @@ -289,11 +288,11 @@
      -

      This list is not complete but does represent those bugs which may effect users on a wider scale. Other bugs listed in the tracker have typically been shown to be limited to certain setups or methods of installation, updating and/or conversions.

      +

      This list is by no means complete but does represent those bugs which may effect users on a wider scale. Other bugs listed in the tracker have typically been shown to be limited to certain setups or methods of installation, updating and/or conversions.

        -
      • Conversions may fail to complete on large boards under some hosts
      • -
      • Updates may fail to complete on large update sets under some hosts
      • +
      • Conversions may fail to complete on large boards under some hosts.
      • +
      • Updates may fail to complete on large update sets under some hosts.
      • Smilies placed directly after bbcode tags will not get parsed. Smilies always need to be separated by spaces.
      @@ -313,9 +312,9 @@
      -

      phpBB is no longer supported on PHP3 due to several compatibility issues and we recommend that you upgrade to the latest stable release of PHP5 to run phpBB. The minimum version required is PHP 4.3.3.

      +

      phpBB is no longer supported on PHP3 due to several compatibility issues and we recommend that you upgrade to the latest stable release of PHP5 to run phpBB. The minimum version required is PHP 4.3.3. The minimum version that will be required for phpBB 3.1 is PHP 5.3.2.

      -

      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.

      +

      Please remember that running any application on a development (unstable, e.g. a beta release) version of PHP can lead to strange/unexpected results which may appear to be bugs in the application. Therefore, we recommend you upgrade to the newest stable version of PHP before running phpBB3. If you are running a development version of PHP please check any bugs you find on a system running a stable release before submitting.

      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 and Firebird. Versions of PHP used range from 4.3.3 to 6.0.0-dev without problem.

      @@ -339,7 +338,7 @@
      -

      This application is opensource software released under the GNU General Public License v2. Please see source code and the docs directory for more details. This package and its contents are Copyright (c) phpBB Group, All Rights Reserved.

      +

      This application is open source software released under the GNU General Public License v2. Please see source code and the docs directory for more details. This package and its contents are Copyright © phpBB Group, All Rights Reserved.

      From 8a2063090c382445835e64fb95ad3aebd777e146 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Thu, 12 Apr 2012 20:53:27 +0100 Subject: [PATCH 002/113] [ticket/10776] Fixed a couple language changes in docs/README.html. PHPBB3-10776 --- phpBB/docs/README.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/docs/README.html b/phpBB/docs/README.html index d54b9d920f..0b5709a7c7 100644 --- a/phpBB/docs/README.html +++ b/phpBB/docs/README.html @@ -136,7 +136,7 @@

      This is the official location for all supported language sets. If you download a package from a 3rd party site you do so with the understanding that we cannot offer support. Please do not ask for support if you download a language pack from a 3rd party site.

      -

      Installation of these packages is straightforward; simply download the required language pack and unarchive it into the languages/ folder. Please ensure you retain the directory structure when doing this! Once uploaded go to the Admin->System->Language Packs and install the new language pack, which will have been automatically detected. To install the style imageset you should download the imageset for your language and unarchive the file/s into the relevant imageset directory (styles/prosilver/imageset or styles/subsilver2/imageset). Again, you must retain the directory structure. Once installed the imageset will immediately become available.

      +

      Installation of these packages is straightforward; simply download the required language pack and extract it into the languages/ folder. Please ensure you retain the directory structure when doing this! Once uploaded go to the Admin->System->Language Packs and install the new language pack, which will have been automatically detected. To install the style imageset you should download the imageset for your language and extract the file/s into the relevant imageset directory (styles/prosilver/imageset or styles/subsilver2/imageset). Again, you must retain the directory structure. Once installed the imageset will immediately become available.

      If your language is not available please visit our forums where you will find a topic listing translations currently available or in preparation. This topic also gives you information should you wish to volunteer to translate a language not currently listed.

      @@ -148,7 +148,7 @@

      Please note that styles for phpBB2 will not work with phpBB3.

      -

      Once you have downloaded a style, the next step is to unarchive (or upload the unarchived contents of) the package into your styles/ directory. You then need to visit Administration -> Styles. You should see the new style, click install and it will become available for all your users.

      +

      Once you have downloaded a style, the next step is to extract (or upload the extracted contents of) the package into your styles/ directory. You then need to visit Administration -> Styles. You should see the new style, click install and it will become available for all your users.

      Please note that if you create your own style or modify existing ones, you should enable the "Recompile stale style components" setting within the Admin->General->Load Settings screen. This setting allows the cache to detect changes made to the style and automatically refresh it. If this setting is disabled, you will not see your changes taking effect without manually refreshing the style components.

      @@ -194,7 +194,7 @@

      http://www.phpbb.com/community/

      -

      If you do seek help via our forums please be sure to do a search before posting to make sure; if someone has experienced the issue before, then you may find that your question has already been answered. Please remember that phpBB is entirely staffed by volunteers, no one receives any compensation for the time they give, including moderators as well as developers; please be respectful and mindful when awaiting responses and receiving support.

      +

      If you do seek help via our forums please be sure to do a search before posting; if someone has experienced the issue before, then you may find that your question has already been answered. Please remember that phpBB is entirely staffed by volunteers, no one receives any compensation for the time they give, including moderators as well as developers; please be respectful and mindful when awaiting responses and receiving support.

      3.iii Internet Relay Chat

      From 170333a6fca0dcc227152b3c8da79fad3bd6f475 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 11 May 2013 22:49:42 +0300 Subject: [PATCH 003/113] [ticket/10772] Use forum specific style for trigger_error PHPBB3-10772 --- phpBB/viewtopic.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 74420a25c7..90625d3f99 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -146,7 +146,15 @@ if ($view && !$post_id) if (!$row) { - $user->setup('viewtopic'); + // Check for forum style + $sql = 'SELECT forum_style + FROM ' . FORUMS_TABLE . " + WHERE forum_id = $forum_id"; + $result = $db->sql_query($sql); + $forum_style = (int) $db->sql_fetchfield('forum_style'); + $db->sql_freeresult($result); + + $user->setup('viewtopic', $forum_style); trigger_error(($view == 'next') ? 'NO_NEWER_TOPICS' : 'NO_OLDER_TOPICS'); } else From 56ac97e819d0a31d24120bf4f92f2547fad000a2 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 16 May 2013 09:24:16 +0300 Subject: [PATCH 004/113] [ticket/10772] Functional tests for forum style PHPBB3-10772 --- tests/functional/forum_style_test.php | 51 +++++++++ .../phpbb_functional_test_case.php | 103 ++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 tests/functional/forum_style_test.php diff --git a/tests/functional/forum_style_test.php b/tests/functional/forum_style_test.php new file mode 100644 index 0000000000..5d95538f68 --- /dev/null +++ b/tests/functional/forum_style_test.php @@ -0,0 +1,51 @@ +request('GET', 'viewtopic.php?t=1&f=2'); + $this->assert_response_success(); + $this->assertContains('styles/prosilver/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + + $crawler = $this->request('GET', 'viewtopic.php?t=1'); + $this->assert_response_success(); + $this->assertContains('styles/prosilver/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + + $crawler = $this->request('GET', 'viewtopic.php?t=1&view=next'); + $this->assert_response_success(); + $this->assertContains('styles/prosilver/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + } + + public function test_custom_forum_style() + { + $db = $this->get_db(); + $this->add_style(2, 'test_style'); + $db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET forum_style = 2 WHERE forum_id = 2'); + + $crawler = $this->request('GET', 'viewtopic.php?t=1&f=2'); + $this->assert_response_success(); + $this->assertContains('styles/test_style/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + + $crawler = $this->request('GET', 'viewtopic.php?t=1'); + $this->assert_response_success(); + $this->assertContains('styles/test_style/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + + $crawler = $this->request('GET', 'viewtopic.php?t=1&view=next'); + $this->assert_response_success(); + $this->assertContains('styles/test_style/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); + + $db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET forum_style = 0 WHERE forum_id = 2'); + $this->delete_style(2, 'test_style'); + } +} diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 83c931f924..c2904c93e1 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -225,6 +225,109 @@ class phpbb_functional_test_case extends phpbb_test_case $db_conn_mgr->recreate_db(); } + /** + * Creates a new style + * + * @param string $style_id Style ID + * @param string $style_path Style directory + * @param string $parent_style_id Parent style id. Default = 1 + * @param string $parent_style_path Parent style directory. Default = 'prosilver' + */ + protected function add_style($style_id, $style_path, $parent_style_id = 1, $parent_style_path = 'prosilver') + { + global $phpbb_root_path; + + $db = $this->get_db(); + if (version_compare(PHPBB_VERSION, '3.1.0-dev', '<')) + { + $sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'style_id' => $style_id, + 'style_name' => $style_path, + 'style_copyright' => '', + 'style_active' => 1, + 'template_id' => $style_id, + 'theme_id' => $style_id, + 'imageset_id' => $style_id, + )); + $db->sql_query($sql); + + $sql = 'INSERT INTO ' . STYLES_IMAGESET_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'imageset_id' => $style_id, + 'imageset_name' => $style_path, + 'imageset_copyright' => '', + 'imageset_path' => $style_path, + )); + $db->sql_query($sql); + + $sql = 'INSERT INTO ' . STYLES_TEMPLATE_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'template_id' => $style_id, + 'template_name' => $style_path, + 'template_copyright' => '', + 'template_path' => $style_path, + 'bbcode_bitfield' => 'kNg=', + 'template_inherits_id' => $parent_style_id, + 'template_inherit_path' => $parent_style_path, + )); + $db->sql_query($sql); + + $sql = 'INSERT INTO ' . STYLES_THEME_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'theme_id' => $style_id, + 'theme_name' => $style_path, + 'theme_copyright' => '', + 'theme_path' => $style_path, + 'theme_storedb' => 0, + 'theme_mtime' => 0, + 'theme_data' => '', + )); + $db->sql_query($sql); + + if ($style_path != 'prosilver' && $style_path != 'subsilver2') + { + @mkdir($phpbb_root_path . 'styles/' . $style_path, 0777); + @mkdir($phpbb_root_path . 'styles/' . $style_path . '/template', 0777); + } + } + else + { + $db->sql_multi_insert(STYLES_TABLE, array( + 'style_id' => $style_id, + 'style_name' => $style_path, + 'style_copyright' => '', + 'style_active' => 1, + 'style_path' => $style_path, + 'bbcode_bitfield' => 'kNg=', + 'style_parent_id' => $parent_style_id, + 'style_parent_tree' => $parent_style_path, + )); + } + } + + /** + * Remove temporary style created by add_style() + * + * @param string $style_id Style ID + * @param string $style_path Style directory + */ + protected function delete_style($style_id, $style_path) + { + global $phpbb_root_path; + + $db = $this->get_db(); + $db->sql_query('DELETE FROM ' . STYLES_TABLE . ' WHERE style_id = ' . $style_id); + if (version_compare(PHPBB_VERSION, '3.1.0-dev', '<')) + { + $db->sql_query('DELETE FROM ' . STYLES_IMAGESET_TABLE . ' WHERE imageset_id = ' . $style_id); + $db->sql_query('DELETE FROM ' . STYLES_TEMPLATE_TABLE . ' WHERE template_id = ' . $style_id); + $db->sql_query('DELETE FROM ' . STYLES_THEME_TABLE . ' WHERE theme_id = ' . $style_id); + + if ($style_path != 'prosilver' && $style_path != 'subsilver2') + { + @rmdir($phpbb_root_path . 'styles/' . $style_path . '/template'); + @rmdir($phpbb_root_path . 'styles/' . $style_path); + } + } + } + /** * Creates a new user with limited permissions * From 1ea1247cd583e1f3f45a4b83310dc3e934caf00d Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 16 May 2013 09:34:58 +0300 Subject: [PATCH 005/113] [ticket/10772] Remove unnecessary comment PHPBB3-10772 --- phpBB/viewtopic.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 90625d3f99..fb12dd925a 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -146,7 +146,6 @@ if ($view && !$post_id) if (!$row) { - // Check for forum style $sql = 'SELECT forum_style FROM ' . FORUMS_TABLE . " WHERE forum_id = $forum_id"; From 8191755cca418ad2124e11e4e93559b9cad7d8bd Mon Sep 17 00:00:00 2001 From: erangamapa Date: Sat, 25 May 2013 10:50:43 +0530 Subject: [PATCH 006/113] [ticket/11145] Wrong error thrown when uploading a bigger image. When attaching an image to a post with a size larger than maximum defined in php.ini, 'ATTACHED_IMAGE_NOT_IMAGE' error is thrown. $file->is_image() is returning false value when image size is too large. Therefore, moved not image test down after image size test. PHPBB3-11145 --- phpBB/includes/functions_posting.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index e5cbae0d71..2e5130c5b8 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -423,16 +423,6 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage $cat_id = (isset($extensions[$file->get('extension')]['display_cat'])) ? $extensions[$file->get('extension')]['display_cat'] : ATTACHMENT_CATEGORY_NONE; - // Make sure the image category only holds valid images... - if ($cat_id == ATTACHMENT_CATEGORY_IMAGE && !$file->is_image()) - { - $file->remove(); - - // If this error occurs a user tried to exploit an IE Bug by renaming extensions - // Since the image category is displaying content inline we need to catch this. - trigger_error($user->lang['ATTACHED_IMAGE_NOT_IMAGE']); - } - // Do we have to create a thumbnail? $filedata['thumbnail'] = ($cat_id == ATTACHMENT_CATEGORY_IMAGE && $config['img_create_thumbnail']) ? 1 : 0; @@ -473,6 +463,16 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage return $filedata; } + // Make sure the image category only holds valid images... + if ($cat_id == ATTACHMENT_CATEGORY_IMAGE && !$file->is_image()) + { + $file->remove(); + + // If this error occurs a user tried to exploit an IE Bug by renaming extensions + // Since the image category is displaying content inline we need to catch this. + trigger_error($user->lang['ATTACHED_IMAGE_NOT_IMAGE']); + } + $filedata['filesize'] = $file->get('filesize'); $filedata['mimetype'] = $file->get('mimetype'); $filedata['extension'] = $file->get('extension'); From 5dcf028cf0791956be0a8cb5f8ea82d3cd91080a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 26 May 2013 21:12:32 +0200 Subject: [PATCH 007/113] [ticket/11568] Use Goutte Client to install the board for functional tests PHPBB3-11568 --- .../phpbb_functional_test_case.php | 144 +++++++++++++----- 1 file changed, 105 insertions(+), 39 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index b1352b247e..cd3133f3a0 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -17,6 +17,9 @@ class phpbb_functional_test_case extends phpbb_test_case protected $client; protected $root_url; + static protected $static_client; + static protected $static_root_url; + protected $cache = null; protected $db = null; @@ -77,6 +80,11 @@ class phpbb_functional_test_case extends phpbb_test_case return $this->client->request($method, $this->root_url . $path); } + static public function static_request($method, $path) + { + return self::$static_client->request($method, self::$static_root_url . $path); + } + // bootstrap, called after board is set up // once per test case class // test cases can override this @@ -148,28 +156,78 @@ class phpbb_functional_test_case extends phpbb_test_case } } - // begin data - $data = array(); + $cookieJar = new CookieJar; + self::$static_client = new Goutte\Client(array(), null, $cookieJar); - $data = array_merge($data, self::$config); - - $data = array_merge($data, array( - 'default_lang' => 'en', - 'admin_name' => 'admin', - 'admin_pass1' => 'admin', - 'admin_pass2' => 'admin', - 'board_email' => 'nobody@example.com', - )); + // Reset the curl handle because it is 0 at this point and not a valid + // resource + self::$static_client->getClient()->getCurlMulti()->reset(true); + self::$static_root_url = self::$config['phpbb_functional_url']; $parseURL = parse_url(self::$config['phpbb_functional_url']); - $data = array_merge($data, array( - 'email_enable' => false, - 'smtp_delivery' => false, - 'smtp_host' => '', - 'smtp_auth' => '', - 'smtp_user' => '', - 'smtp_pass' => '', + $crawler = self::static_request('GET', 'install/index.php?mode=install'); + self::static_assert_response_success(); + self::assertContains('Welcome to Installation', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('Installation compatibility', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('Database configuration', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(array( + // Installer uses 3.0-style dbms name + 'dbms' => str_replace('phpbb_db_driver_', '', self::$config['dbms']), + 'dbhost' => self::$config['dbhost'], + 'dbport' => self::$config['dbport'], + 'dbname' => self::$config['dbname'], + 'dbuser' => self::$config['dbuser'], + 'dbpasswd' => self::$config['dbpasswd'], + 'table_prefix' => self::$config['table_prefix'], + )); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('Successful connection', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('Administrator configuration', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(array( + 'default_lang' => 'en', + 'admin_name' => 'admin', + 'admin_pass1' => 'adminadmin', + 'admin_pass2' => 'adminadmin', + 'board_email1' => 'nobody@example.com', + 'board_email2' => 'nobody@example.com', + )); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('Tests passed', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); + file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true)); + $form = $crawler->selectButton('submit')->form(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(array( + 'email_enable' => true, + 'smtp_delivery' => true, + 'smtp_host' => 'nxdomain.phpbb.com', + 'smtp_auth' => 'PLAIN', + 'smtp_user' => 'nxuser', + 'smtp_pass' => 'nxpass', 'cookie_secure' => false, 'force_server_vars' => false, 'server_protocol' => $parseURL['scheme'] . '://', @@ -177,26 +235,16 @@ class phpbb_functional_test_case extends phpbb_test_case 'server_port' => isset($parseURL['port']) ? (int) $parseURL['port'] : 80, 'script_path' => $parseURL['path'], )); - // end data - $content = self::do_request('install'); - self::assertNotSame(false, $content); - self::assertContains('Welcome to Installation', $content); + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('The database tables used by phpBB', $crawler->filter('#main')->text()); + self::assertContains('have been created and populated with some initial data.', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); - $content = self::do_request('create_table', $data); - self::assertNotSame(false, $content); - self::assertContains('The database tables used by phpBB', $content); - // 3.0 or 3.1 - self::assertContains('have been created and populated with some initial data.', $content); - - $content = self::do_request('config_file', $data); - self::assertNotSame(false, $content); - self::assertContains('Configuration file', $content); - file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true, true)); - - $content = self::do_request('final', $data); - self::assertNotSame(false, $content); - self::assertContains('You have successfully installed', $content); + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('You have successfully installed', $crawler->text()); copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); } @@ -270,7 +318,7 @@ class phpbb_functional_test_case extends phpbb_test_case 'user_lang' => 'en', 'user_timezone' => 0, 'user_dateformat' => '', - 'user_password' => phpbb_hash($username), + 'user_password' => phpbb_hash($username . $username), ); return user_add($user_row); } @@ -283,7 +331,7 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text()); $form = $crawler->selectButton($this->lang('LOGIN'))->form(); - $crawler = $this->client->submit($form, array('username' => $username, 'password' => $username)); + $crawler = $this->client->submit($form, array('username' => $username, 'password' => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); @@ -323,7 +371,7 @@ class phpbb_functional_test_case extends phpbb_test_case { if (strpos($field, 'password_') === 0) { - $crawler = $this->client->submit($form, array('username' => $username, $field => $username)); + $crawler = $this->client->submit($form, array('username' => $username, $field => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); @@ -397,4 +445,22 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertNotContains('Warning:', $content); $this->assertNotContains('[phpBB Debug]', $content); } + + /** + * 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 + */ + static public function static_assert_response_success() + { + self::assertEquals(200, self::$static_client->getResponse()->getStatus()); + $content = self::$static_client->getResponse()->getContent(); + self::assertNotContains('Fatal error:', $content); + self::assertNotContains('Notice:', $content); + //@todo: self::assertNotContains('Warning:', $content); + self::assertNotContains('[phpBB Debug]', $content); + } } From a3e5efc63483f06c6d66296adbd0538d59a05a21 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 26 May 2013 21:16:49 +0200 Subject: [PATCH 008/113] [ticket/11568] Set client manually so we can increase the cURL timeout PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index cd3133f3a0..b622c6e284 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -158,6 +158,13 @@ class phpbb_functional_test_case extends phpbb_test_case $cookieJar = new CookieJar; self::$static_client = new Goutte\Client(array(), null, $cookieJar); + // Set client manually so we can increase the cURL timeout + self::$static_client->setClient(new Guzzle\Http\Client('', array( + Guzzle\Http\Client::DISABLE_REDIRECTS => true, + 'curl.options' => array( + CURLOPT_TIMEOUT => 120 + ), + ))); // Reset the curl handle because it is 0 at this point and not a valid // resource From f25389f94a46bb63d8688be9eef699de9853b4fc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 26 May 2013 23:57:50 +0200 Subject: [PATCH 009/113] [ticket/11568] Any output before the doc type means there was an error Change is needed to allow "Warning:" in the HTML body PHPBB3-11568 --- .../test_framework/phpbb_functional_test_case.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index b622c6e284..8a386d1db7 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -447,10 +447,9 @@ class phpbb_functional_test_case extends phpbb_test_case { $this->assertEquals(200, $this->client->getResponse()->getStatus()); $content = $this->client->getResponse()->getContent(); - $this->assertNotContains('Fatal error:', $content); - $this->assertNotContains('Notice:', $content); - $this->assertNotContains('Warning:', $content); - $this->assertNotContains('[phpBB Debug]', $content); + + // Any output before the doc type means there was an error + $this->assertEquals(0, strpos($content, 'getResponse()->getStatus()); $content = self::$static_client->getResponse()->getContent(); - self::assertNotContains('Fatal error:', $content); - self::assertNotContains('Notice:', $content); - //@todo: self::assertNotContains('Warning:', $content); - self::assertNotContains('[phpBB Debug]', $content); + + // Any output before the doc type means there was an error + self::assertEquals(0, strpos($content, ' Date: Mon, 27 May 2013 22:09:44 +0200 Subject: [PATCH 010/113] [ticket/11568] Only use a static version of the client PHPBB3-11568 --- .../phpbb_functional_test_case.php | 119 +++++++++--------- 1 file changed, 60 insertions(+), 59 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 8a386d1db7..0d122604fd 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -14,11 +14,8 @@ require_once __DIR__ . '/../../phpBB/includes/cache.php'; class phpbb_functional_test_case extends phpbb_test_case { - protected $client; - protected $root_url; - - static protected $static_client; - static protected $static_root_url; + static protected $client; + static protected $root_url; protected $cache = null; protected $db = null; @@ -43,6 +40,7 @@ class phpbb_functional_test_case extends phpbb_test_case parent::setUpBeforeClass(); self::$config = phpbb_test_case_helpers::get_test_config(); + self::$root_url = self::$config['phpbb_functional_url']; if (!isset(self::$config['phpbb_functional_url'])) { @@ -63,11 +61,11 @@ class phpbb_functional_test_case extends phpbb_test_case $this->bootstrap(); $this->cookieJar = new CookieJar; - $this->client = new Goutte\Client(array(), null, $this->cookieJar); + self::$client = new Goutte\Client(array(), null, $this->cookieJar); // Reset the curl handle because it is 0 at this point and not a valid // resource - $this->client->getClient()->getCurlMulti()->reset(true); - $this->root_url = self::$config['phpbb_functional_url']; + self::$client->getClient()->getCurlMulti()->reset(true); + // Clear the language array so that things // that were added in other tests are gone $this->lang = array(); @@ -75,14 +73,45 @@ class phpbb_functional_test_case extends phpbb_test_case $this->purge_cache(); } - public function request($method, $path) + /** + * Perform a request to page + * + * @param string $method HTTP Method + * @param string $path Page path, relative from phpBB root path + * @param array $form_data An array of form field values + * @param bool $skip_assert_response_success Should we skip the basic response assertions? + * @return Symfony\Component\DomCrawler\Crawler + */ + static public function request($method, $path, $form_data = array(), $skip_assert_response_success = false) { - return $this->client->request($method, $this->root_url . $path); + $crawler = self::$client->request($method, self::$root_url . $path, $form_data); + + if (!$skip_assert_response_success) + { + self::assert_response_success(); + } + + return $crawler; } - static public function static_request($method, $path) + /** + * Submits a form + * + * @param Symfony\Component\DomCrawler\Form $form A Form instance + * @param array $values An array of form field values + * @param bool $skip_assert_response_success Should we skip the basic response assertions? + * @return Symfony\Component\DomCrawler\Crawler + */ + static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $skip_assert_response_success = false) { - return self::$static_client->request($method, self::$static_root_url . $path); + $crawler = self::$client->submit($form, $values); + + if (!$skip_assert_response_success) + { + self::assert_response_success(); + } + + return $crawler; } // bootstrap, called after board is set up @@ -157,9 +186,9 @@ class phpbb_functional_test_case extends phpbb_test_case } $cookieJar = new CookieJar; - self::$static_client = new Goutte\Client(array(), null, $cookieJar); + self::$client = new Goutte\Client(array(), null, $cookieJar); // Set client manually so we can increase the cURL timeout - self::$static_client->setClient(new Guzzle\Http\Client('', array( + self::$client->setClient(new Guzzle\Http\Client('', array( Guzzle\Http\Client::DISABLE_REDIRECTS => true, 'curl.options' => array( CURLOPT_TIMEOUT => 120 @@ -168,23 +197,19 @@ class phpbb_functional_test_case extends phpbb_test_case // Reset the curl handle because it is 0 at this point and not a valid // resource - self::$static_client->getClient()->getCurlMulti()->reset(true); - self::$static_root_url = self::$config['phpbb_functional_url']; + self::$client->getClient()->getCurlMulti()->reset(true); $parseURL = parse_url(self::$config['phpbb_functional_url']); - $crawler = self::static_request('GET', 'install/index.php?mode=install'); - self::static_assert_response_success(); + $crawler = self::request('GET', 'install/index.php?mode=install'); self::assertContains('Welcome to Installation', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('Installation compatibility', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('Database configuration', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( // Installer uses 3.0-style dbms name @@ -197,13 +222,11 @@ class phpbb_functional_test_case extends phpbb_test_case 'table_prefix' => self::$config['table_prefix'], )); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('Successful connection', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('Administrator configuration', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( 'default_lang' => 'en', @@ -214,19 +237,16 @@ class phpbb_functional_test_case extends phpbb_test_case 'board_email2' => 'nobody@example.com', )); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('Tests passed', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true)); $form = $crawler->selectButton('submit')->form(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( 'email_enable' => true, @@ -243,14 +263,12 @@ class phpbb_functional_test_case extends phpbb_test_case 'script_path' => $parseURL['path'], )); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('The database tables used by phpBB', $crawler->filter('#main')->text()); self::assertContains('have been created and populated with some initial data.', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('You have successfully installed', $crawler->text()); copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); } @@ -338,7 +356,7 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text()); $form = $crawler->selectButton($this->lang('LOGIN'))->form(); - $crawler = $this->client->submit($form, array('username' => $username, 'password' => $username . $username)); + $crawler = $this->submit($form, array('username' => $username, 'password' => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); @@ -378,7 +396,7 @@ class phpbb_functional_test_case extends phpbb_test_case { if (strpos($field, 'password_') === 0) { - $crawler = $this->client->submit($form, array('username' => $username, $field => $username . $username)); + $crawler = $this->submit($form, array('username' => $username, $field => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); @@ -443,29 +461,12 @@ class phpbb_functional_test_case extends phpbb_test_case * * @return null */ - public function assert_response_success() + static public function assert_response_success() { - $this->assertEquals(200, $this->client->getResponse()->getStatus()); - $content = $this->client->getResponse()->getContent(); + self::assertEquals(200, self::$client->getResponse()->getStatus()); + $content = self::$client->getResponse()->getContent(); // Any output before the doc type means there was an error - $this->assertEquals(0, strpos($content, 'getResponse()->getStatus()); - $content = self::$static_client->getResponse()->getContent(); - - // Any output before the doc type means there was an error - self::assertEquals(0, strpos($content, ' Date: Mon, 27 May 2013 22:12:50 +0200 Subject: [PATCH 011/113] [ticket/11568] Remove manual calls to assert_response_success() PHPBB3-11568 --- tests/functional/auth_test.php | 4 ---- tests/functional/browse_test.php | 3 --- tests/functional/posting_test.php | 5 +---- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php index 662b1bd38b..a0c909e798 100644 --- a/tests/functional/auth_test.php +++ b/tests/functional/auth_test.php @@ -18,7 +18,6 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case // check for logout link $crawler = $this->request('GET', 'index.php'); - $this->assert_response_success(); $this->assertContains($this->lang('LOGOUT_USER', 'admin'), $crawler->filter('.navbar')->text()); } @@ -27,7 +26,6 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case $this->create_user('anothertestuser'); $this->login('anothertestuser'); $crawler = $this->request('GET', 'index.php'); - $this->assert_response_success(); $this->assertContains('anothertestuser', $crawler->filter('.icon-logout')->text()); } @@ -41,12 +39,10 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case // logout $crawler = $this->request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); - $this->assert_response_success(); $this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text()); // look for a register link, which should be visible only when logged out $crawler = $this->request('GET', 'index.php'); - $this->assert_response_success(); $this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text()); } } diff --git a/tests/functional/browse_test.php b/tests/functional/browse_test.php index b5748059c6..26c18c4c1f 100644 --- a/tests/functional/browse_test.php +++ b/tests/functional/browse_test.php @@ -15,21 +15,18 @@ 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/posting_test.php b/tests/functional/posting_test.php index d05207edf0..5cf7559245 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -30,7 +30,6 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case // Test quoting a message $crawler = $this->request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}"); - $this->assert_response_success(); $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); } @@ -95,7 +94,6 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case $this->add_lang('posting'); $crawler = $this->request('GET', $posting_url); - $this->assert_response_success(); $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); $hidden_fields = array( @@ -119,8 +117,7 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case // I use a request because the form submission method does not allow you to send data that is not // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) // Instead, I send it as a request with the submit button "post" set to true. - $crawler = $this->client->request('POST', $posting_url, $form_data); - $this->assert_response_success(); + $crawler = $this->request('POST', $posting_url, $form_data); $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); $url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri(); From da98866c24572031b2deda4e8a50cac07efdef5d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 27 May 2013 22:25:25 +0200 Subject: [PATCH 012/113] [ticket/11568] Make CookieJar static aswell PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 0d122604fd..1725a45e38 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -15,6 +15,7 @@ require_once __DIR__ . '/../../phpBB/includes/cache.php'; class phpbb_functional_test_case extends phpbb_test_case { static protected $client; + static protected $cookieJar; static protected $root_url; protected $cache = null; @@ -60,8 +61,8 @@ class phpbb_functional_test_case extends phpbb_test_case $this->bootstrap(); - $this->cookieJar = new CookieJar; - self::$client = new Goutte\Client(array(), null, $this->cookieJar); + self::$cookieJar = new CookieJar; + self::$client = new Goutte\Client(array(), null, self::$cookieJar); // Reset the curl handle because it is 0 at this point and not a valid // resource self::$client->getClient()->getCurlMulti()->reset(true); @@ -185,8 +186,8 @@ class phpbb_functional_test_case extends phpbb_test_case } } - $cookieJar = new CookieJar; - self::$client = new Goutte\Client(array(), null, $cookieJar); + self::$cookieJar = new CookieJar; + self::$client = new Goutte\Client(array(), null, self::$cookieJar); // Set client manually so we can increase the cURL timeout self::$client->setClient(new Guzzle\Http\Client('', array( Guzzle\Http\Client::DISABLE_REDIRECTS => true, @@ -360,7 +361,7 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); - $cookies = $this->cookieJar->all(); + $cookies = self::$cookieJar->all(); // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie foreach ($cookies as $cookie); @@ -400,7 +401,7 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); - $cookies = $this->cookieJar->all(); + $cookies = self::$cookieJar->all(); // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie foreach ($cookies as $cookie); From 9be57ec076eb1c819c6a6a51c4f2ba9f3e3c915d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 27 May 2013 22:33:48 +0200 Subject: [PATCH 013/113] [ticket/11568] Fix common_groups_test.php form handling PHPBB3-11568 --- tests/functional/common_groups_test.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/functional/common_groups_test.php b/tests/functional/common_groups_test.php index 7ccd78421e..6e1f1afdce 100644 --- a/tests/functional/common_groups_test.php +++ b/tests/functional/common_groups_test.php @@ -36,10 +36,9 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test // Manage Administrators group $crawler = $this->request('GET', $this->get_url() . '&g=5&sid=' . $this->sid); - $this->assert_response_success(); $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); $form['group_colour']->setValue($input); - $crawler = $this->client->submit($form); + $crawler = $this->submit($form); $this->assertContains($this->lang($expected), $crawler->text()); } } From 3d6620f0db5dbbf9b1f59ec865854a1dcd2e3179 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 28 May 2013 14:10:27 +0200 Subject: [PATCH 014/113] [ticket/11568] Trim the output to allow Tabs before INCLUDE overall_header PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 1725a45e38..4ebe1d2d17 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -468,6 +468,6 @@ class phpbb_functional_test_case extends phpbb_test_case $content = self::$client->getResponse()->getContent(); // Any output before the doc type means there was an error - self::assertStringStartsWith(' Date: Tue, 28 May 2013 14:38:28 +0200 Subject: [PATCH 015/113] [ticket/11568] Allow different status codes PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 4ebe1d2d17..e87f53caed 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -462,9 +462,9 @@ class phpbb_functional_test_case extends phpbb_test_case * * @return null */ - static public function assert_response_success() + static public function assert_response_success($status_code = 200) { - self::assertEquals(200, self::$client->getResponse()->getStatus()); + self::assertEquals($status_code, self::$client->getResponse()->getStatus()); $content = self::$client->getResponse()->getContent(); // Any output before the doc type means there was an error From e84fb0c6cacdd4da2542bb94e5994d1962930ca4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 28 May 2013 14:47:24 +0200 Subject: [PATCH 016/113] [ticket/11568] Add method to get page content PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index e87f53caed..63cbeb515a 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -115,6 +115,16 @@ class phpbb_functional_test_case extends phpbb_test_case return $crawler; } + /** + * Get Client Content + * + * @return string HTML page + */ + static public function get_content() + { + return self::$client->getResponse()->getContent(); + } + // bootstrap, called after board is set up // once per test case class // test cases can override this From 3d625ab0cf9fe8d1869fbdd66a4602553bb744d4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 29 May 2013 18:24:54 +0200 Subject: [PATCH 017/113] [ticket/11579] Add basic set of unit tests for validate_data() This currently includes tests for the string, num, date, match, and language iso validation functions. PHPBB3-11579 --- tests/functions/validate_data_test.php | 252 +++++++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 tests/functions/validate_data_test.php diff --git a/tests/functions/validate_data_test.php b/tests/functions/validate_data_test.php new file mode 100644 index 0000000000..6a429a5529 --- /dev/null +++ b/tests/functions/validate_data_test.php @@ -0,0 +1,252 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/language_select.xml'); + } + + /** + * Test provided input data with supplied checks and compare to expected + * results + * + * @param array $input Input data with specific array keys that need to + * be matched by the ones in the other 2 params + * @param array $validate_check Array containing validate_data check + * settings, i.e. array('foobar' => array('string')) + * @param array $expected Array containing the expected results. Either + * an array containing the error message or the an empty + * array if input is correct + */ + public function validate_data_check($input, $validate_check, $expected) + { + foreach ($input as $key => $data) + { + $this->assertEquals($expected[$key], validate_data(array($data), array($validate_check[$key]))); + } + } + + /* + * Types to test + * - string: + * empty + optional = true --> good + * empty + optional = false --> good (min = 0) + * 'foobar' --> good + * 'foobar' + optional = false|true + min = 2 + max = 6 --> good + * 'foobar' + " + min = 7 + max = 9 --> TOO_SHORT + * 'foobar' + " + min = 2 + max = 5 --> TOO_LONG + * '' + optional = false + min = 1 + max = 6 --> TOO_SHORT + * '' + optional = true + min = 1 + max = 6 --> good + */ + public function test_validate_string() + { + $this->validate_data_check(array( + 'empty_opt' => '', + 'empty' => '', + 'foo' => 'foobar', + 'foo_minmax_correct' => 'foobar', + 'foo_minmax_short' => 'foobar', + 'foo_minmax_long' => 'foobar', + 'empty_short' => '', + 'empty_length_opt' => '', + ), + array( + 'empty_opt' => array('string', true), + 'empty' => array('string'), + 'foo' => array('string'), + 'foo_minmax_correct' => array('string', false, 2, 6), + 'foo_minmax_short' => array('string', false, 7, 9), + 'foo_minmax_long' => array('string', false, 2, 5), + 'empty_short' => array('string', false, 1, 6), + 'empty_length_opt' => array('string', true, 1, 6), + ), + array( + 'empty_opt' => array(), + 'empty' => array(), + 'foo' => array(), + 'foo_minmax_correct' => array(), + 'foo_minmax_short' => array('TOO_SHORT'), + 'foo_minmax_long' => array('TOO_LONG'), + 'empty_short' => array('TOO_SHORT'), + 'empty_length_opt' => array(), + )); + } + + /* + * Types to test + * - num + * empty + optional = true|false --> good + * 0 --> good + * 5 + optional = false|true + min = 2 + max = 6 --> good + * 5 + optional = false|true + min = 7 + max = 10 --> TOO_SMALL + * 5 + optional = false|true + min = 2 + max = 3 --> TOO_LARGE + * 'foobar' --> should fail with WRONG_DATA_NUMERIC !!! + */ + public function test_validate_num() + { + $this->validate_data_check(array( + 'empty' => '', + 'zero' => 0, + 'five_minmax_correct' => 5, + 'five_minmax_short' => 5, + 'five_minmax_long' => 5, + 'string' => 'foobar', + ), + array( + 'empty' => array('num'), + 'zero' => array('num'), + 'five_minmax_correct' => array('num', false, 2, 6), + 'five_minmax_short' => array('num', false, 7, 10), + 'five_minmax_long' => array('num', false, 2, 3), + 'string' => array('num'), + ), + array( + 'empty' => array(), + 'zero' => array(), + 'five_minmax_correct' => array(), + 'five_minmax_short' => array('TOO_SMALL'), + 'five_minmax_long' => array('TOO_LARGE'), + 'string' => array(), + )); + } + + /* + * Types to test + * - date + * . '' --> invalid + * . '' + optional = true --> good + * . 17-06-1990 --> good + * . 05-05-1990 --> good + * . 17-12-1990 --> good + * . 01-01-0000 --> good!!! + * . 17-17-1990 --> invalid + * . 00-12-1990 --> invalid + * . 01-00-1990 --> invalid + */ + public function test_validate_date() + { + $this->validate_data_check(array( + 'empty' => '', + 'empty_opt' => '', + 'double_single' => '17-06-1990', + 'single_single' => '05-05-2009', + 'double_double' => '17-12-1990', + // Currently fails + //'zero_year' => '01-01-0000', + 'month_high' => '17-17-1990', + 'month_low' => '01-00-1990', + 'day_high' => '64-01-1990', + 'day_low' => '00-12-1990', + ), + array( + 'empty' => array('date'), + 'empty_opt' => array('date', true), + 'double_single' => array('date'), + 'single_single' => array('date'), + 'double_double' => array('date'), + // Currently fails + //'zero_year' => array('date'), + 'month_high' => array('date'), + 'month_low' => array('date'), + 'day_high' => array('date'), + 'day_low' => array('date'), + ), + array( + 'empty' => array('INVALID'), + 'empty_opt' => array(), + 'double_single' => array(), + 'single_single' => array(), + 'double_double' => array(), + // Currently fails + //'zero_year' => array(), + 'month_high' => array('INVALID'), + 'month_low' => array('INVALID'), + 'day_high' => array('INVALID'), + 'day_low' => array('INVALID'), + )); + } + + /* + * Types to test + * - match + * . empty + optional = true --> good + * . empty + empty match --> good + * . 'test' + optional = true|false + match = '/[a-z]/' --> good + * . 'test123' + optional = true|false + match = '/[a-z]/' --> WRONG_DATA_MATCH + */ + public function test_validate_match() + { + $this->validate_data_check(array( + 'empty_opt' => '', + 'empty_empty_match' => '', + 'foobar' => 'foobar', + 'foobar_fail' => 'foobar123', + ), + array( + 'empty_opt' => array('match', true, '/[a-z]$/'), + 'empty_empty_match' => array('match'), + 'foobar' => array('match', false, '/[a-z]$/'), + 'foobar_fail' => array('match', false, '/[a-z]$/'), + ), + array( + 'empty_opt' => array(), + 'empty_empty_match' => array(), + 'foobar' => array(), + 'foobar_fail' => array('WRONG_DATA'), + )); + } + + /* + * Types to test + * - language_iso_name + * . empty --> WRONG_DATA + * . 'en' --> good + * . 'cs' --> good + * . 'de' --> WRONG_DATA (won't exist) + */ + public function test_validate_lang_iso() + { + global $db; + + $db = $this->new_dbal(); + + $this->validate_data_check(array( + 'empty' => '', + 'en' => 'en', + 'cs' => 'cs', + 'de' => 'de', + ), + array( + 'empty' => array('language_iso_name'), + 'en' => array('language_iso_name'), + 'cs' => array('language_iso_name'), + 'de' => array('language_iso_name'), + ), + array( + 'empty' => array('WRONG_DATA'), + 'en' => array(), + 'cs' => array(), + 'de' => array('WRONG_DATA'), + )); + } +} From 45c91be970f6afc1a5907442cd66e6a3a42a00fc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 30 May 2013 14:12:08 +0200 Subject: [PATCH 018/113] [ticket/11568] Only assert string when doctype is there at all PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 63cbeb515a..304220f243 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -478,6 +478,9 @@ class phpbb_functional_test_case extends phpbb_test_case $content = self::$client->getResponse()->getContent(); // Any output before the doc type means there was an error - self::assertStringStartsWith(' Date: Thu, 30 May 2013 14:16:31 +0200 Subject: [PATCH 019/113] [ticket/11568] Remove unused method PHPBB3-11568 --- .../phpbb_functional_test_case.php | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 304220f243..04a43182ae 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -284,25 +284,6 @@ class phpbb_functional_test_case extends phpbb_test_case copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); } - static private function do_request($sub, $post_data = null) - { - $context = null; - - if ($post_data) - { - $context = stream_context_create(array( - 'http' => array( - 'method' => 'POST', - 'header' => 'Content-Type: application/x-www-form-urlencoded', - 'content' => http_build_query($post_data), - 'ignore_errors' => true, - ), - )); - } - - return file_get_contents(self::$config['phpbb_functional_url'] . 'install/index.php?mode=install&sub=' . $sub, false, $context); - } - static private function recreate_database($config) { $db_conn_mgr = new phpbb_database_test_connection_manager($config); From 3f657bc63e6649da43d860be1848116c42214a65 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 30 May 2013 16:05:19 +0200 Subject: [PATCH 020/113] [ticket/11579] Add remaining unit tests for validate_data functions This now includes tests for usernames, passwords, emails, and jabber addresses. A few small changes had to be applied to phpbb_mock_cache and phpbb_mock_user in order to incorporate needed methods. PHPBB3-11579 --- tests/functions/fixtures/validate_data.xml | 59 ++++ tests/functions/validate_data_test.php | 350 +++++++++++++++++---- tests/mock/cache.php | 15 + tests/mock/user.php | 13 + 4 files changed, 375 insertions(+), 62 deletions(-) create mode 100644 tests/functions/fixtures/validate_data.xml diff --git a/tests/functions/fixtures/validate_data.xml b/tests/functions/fixtures/validate_data.xml new file mode 100644 index 0000000000..38ecae6ad2 --- /dev/null +++ b/tests/functions/fixtures/validate_data.xml @@ -0,0 +1,59 @@ + + + + group_name + group_desc + + foobar_group + test123 + +
      + + lang_id + lang_iso + lang_local_name + lang_english_name + + 1 + en + English + English + + + 2 + cs + Čeština + Czech + +
      + + user_id + username + username_clean + user_permissions + user_sig + user_occ + user_interests + user_email_hash + + 1 + admin + admin + + + + + 143317126117 + + + 2 + moderator + moderator + + + + + 0 + +
      +
      diff --git a/tests/functions/validate_data_test.php b/tests/functions/validate_data_test.php index 6a429a5529..ed91f782ba 100644 --- a/tests/functions/validate_data_test.php +++ b/tests/functions/validate_data_test.php @@ -7,23 +7,30 @@ * */ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; +require_once dirname(__FILE__) . '/../mock/cache.php'; +require_once dirname(__FILE__) . '/../mock/user.php'; class phpbb_functions_validate_data_test extends phpbb_database_test_case { - /* - * Types to test - * - username - * . - * - password - * - email - * - jabber - */ + protected $db; + protected $cache; + protected $user; public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/language_select.xml'); + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/validate_data.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->db = $this->new_dbal(); + $this->cache = new phpbb_mock_cache; + $this->user = new phpbb_mock_user; } /** @@ -42,22 +49,15 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case { foreach ($input as $key => $data) { - $this->assertEquals($expected[$key], validate_data(array($data), array($validate_check[$key]))); + $test = validate_data(array($data), array($validate_check[$key])); + if ($test != $expected[$key]) + { + var_dump($key, $data, $test, $expected[$key]); + } + $this->assertEquals($expected[$key], $test); } } - /* - * Types to test - * - string: - * empty + optional = true --> good - * empty + optional = false --> good (min = 0) - * 'foobar' --> good - * 'foobar' + optional = false|true + min = 2 + max = 6 --> good - * 'foobar' + " + min = 7 + max = 9 --> TOO_SHORT - * 'foobar' + " + min = 2 + max = 5 --> TOO_LONG - * '' + optional = false + min = 1 + max = 6 --> TOO_SHORT - * '' + optional = true + min = 1 + max = 6 --> good - */ public function test_validate_string() { $this->validate_data_check(array( @@ -92,16 +92,6 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case )); } - /* - * Types to test - * - num - * empty + optional = true|false --> good - * 0 --> good - * 5 + optional = false|true + min = 2 + max = 6 --> good - * 5 + optional = false|true + min = 7 + max = 10 --> TOO_SMALL - * 5 + optional = false|true + min = 2 + max = 3 --> TOO_LARGE - * 'foobar' --> should fail with WRONG_DATA_NUMERIC !!! - */ public function test_validate_num() { $this->validate_data_check(array( @@ -130,19 +120,6 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case )); } - /* - * Types to test - * - date - * . '' --> invalid - * . '' + optional = true --> good - * . 17-06-1990 --> good - * . 05-05-1990 --> good - * . 17-12-1990 --> good - * . 01-01-0000 --> good!!! - * . 17-17-1990 --> invalid - * . 00-12-1990 --> invalid - * . 01-00-1990 --> invalid - */ public function test_validate_date() { $this->validate_data_check(array( @@ -186,14 +163,6 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case )); } - /* - * Types to test - * - match - * . empty + optional = true --> good - * . empty + empty match --> good - * . 'test' + optional = true|false + match = '/[a-z]/' --> good - * . 'test123' + optional = true|false + match = '/[a-z]/' --> WRONG_DATA_MATCH - */ public function test_validate_match() { $this->validate_data_check(array( @@ -216,19 +185,11 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case )); } - /* - * Types to test - * - language_iso_name - * . empty --> WRONG_DATA - * . 'en' --> good - * . 'cs' --> good - * . 'de' --> WRONG_DATA (won't exist) - */ public function test_validate_lang_iso() { global $db; - $db = $this->new_dbal(); + $db = $this->db; $this->validate_data_check(array( 'empty' => '', @@ -249,4 +210,269 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case 'de' => array('WRONG_DATA'), )); } + + public function validate_username_data() + { + return array( + array('USERNAME_CHARS_ANY', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array(), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array(), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array(), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('USERNAME_TAKEN') + )), + array('USERNAME_ALPHA_ONLY', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array('INVALID_CHARS'), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array('INVALID_CHARS'), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('INVALID_CHARS') + )), + array('USERNAME_ALPHA_SPACERS', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array(), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array('INVALID_CHARS'), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('USERNAME_TAKEN') + )), + array('USERNAME_LETTER_NUM', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array('INVALID_CHARS'), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array('INVALID_CHARS'), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('INVALID_CHARS') + )), + array('USERNAME_LETTER_NUM_SPACERS', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array(), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array(), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('USERNAME_TAKEN') + )), + array('USERNAME_ASCII', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array(), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array(), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array('INVALID_CHARS'), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('USERNAME_TAKEN') + )), + ); + } + + /** + * @dataProvider validate_username_data + */ + public function test_validate_username($allow_name_chars, $expected) + { + global $cache, $config, $db; + + $db = $this->db; + $cache = $this->cache; + $cache->put('_disallowed_usernames', array('barfoo')); + + $config['allow_name_chars'] = $allow_name_chars; + + $this->validate_data_check(array( + 'foobar_allow' => 'foobar', + 'foobar_ascii' => 'foobar', + 'foobar_any' => 'f*~*^=oo_bar1', + 'foobar_alpha' => 'fo0Bar', + 'foobar_alpha_spacers' => 'Fo0-[B]_a+ R', + 'foobar_letter_num' => 'fo0Bar0', + 'foobar_letter_num_sp' => 'Fö0-[B]_a+ R', + 'foobar_quot' => '"foobar"', + 'barfoo_disallow' => 'barfoo', + 'admin_taken' => 'admin', + 'group_taken' => 'foobar_group', + ), + array( + 'foobar_allow' => array('username', 'foobar'), + 'foobar_ascii' => array('username'), + 'foobar_any' => array('username'), + 'foobar_alpha' => array('username'), + 'foobar_alpha_spacers' => array('username'), + 'foobar_letter_num' => array('username'), + 'foobar_letter_num_sp' => array('username'), + 'foobar_quot' => array('username'), + 'barfoo_disallow' => array('username'), + 'admin_taken' => array('username'), + 'group_taken' => array('username'), + ), + $expected); + } + + public function validate_password_data() + { + return array( + array('PASS_TYPE_ANY', array( + 'empty' => array(), + 'foobar_any' => array(), + 'foobar_mixed' => array(), + 'foobar_alpha' => array(), + 'foobar_symbol' => array(), + )), + array('PASS_TYPE_CASE', array( + 'empty' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_mixed' => array(), + 'foobar_alpha' => array(), + 'foobar_symbol' => array(), + )), + array('PASS_TYPE_ALPHA', array( + 'empty' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_mixed' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_symbol' => array(), + )), + array('PASS_TYPE_SYMBOL', array( + 'empty' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_mixed' => array('INVALID_CHARS'), + 'foobar_alpha' => array('INVALID_CHARS'), + 'foobar_symbol' => array(), + )), + ); + } + + /** + * @dataProvider validate_password_data + */ + public function test_validate_password($pass_complexity, $expected) + { + global $config; + + // Set complexity to mixed case letters, numbers and symbols + $config['pass_complex'] = $pass_complexity; + + $this->validate_data_check(array( + 'empty' => '', + 'foobar_any' => 'foobar', + 'foobar_mixed' => 'FooBar', + 'foobar_alpha' => 'F00bar', + 'foobar_symbol' => 'fooBar123*', + ), + array( + 'empty' => array('password'), + 'foobar_any' => array('password'), + 'foobar_mixed' => array('password'), + 'foobar_alpha' => array('password'), + 'foobar_symbol' => array('password'), + ), + $expected); + } + + public function test_validate_email() + { + global $config, $db, $user; + + $config['email_check_mx'] = true; + $db = $this->db; + $user = $this->user; + $user->optionset('banned_users', array('banned@example.com')); + + $this->validate_data_check(array( + 'empty' => '', + 'allowed' => 'foobar@example.com', + 'invalid' => 'fööbar@example.com', + 'valid_complex' => "'%$~test@example.com", + 'taken' => 'admin@example.com', + 'banned' => 'banned@example.com', + 'no_mx' => 'test@wwrrrhhghgghgh.ttv', + ), + array( + 'empty' => array('email'), + 'allowed' => array('email', 'foobar@example.com'), + 'invalid' => array('email'), + 'valid_complex' => array('email'), + 'taken' => array('email'), + 'banned' => array('email'), + 'no_mx' => array('email'), + ), + array( + 'empty' => array(), + 'allowed' => array(), + 'invalid' => array('EMAIL_INVALID'), + 'valid_complex' => array(), + 'taken' => array('EMAIL_TAKEN'), + 'banned' => array('EMAIL_BANNED'), + 'no_mx' => array('DOMAIN_NO_MX_RECORD'), + )); + } + + public function test_validate_jabber() + { + $this->validate_data_check(array( + 'empty' => '', + 'no_seperator' => 'testjabber.ccc', + 'no_user' => '@jabber.ccc', + 'no_realm' => 'user@', + 'dot_realm' => 'user@.....', + '-realm' => 'user@-jabber.ccc', + 'realm-' => 'user@jabber.ccc-', + 'correct' => 'user@jabber.09A-z.org', + 'prohibited' => 'u@ser@jabber.ccc.org', + 'prohibited_char' => 'uer@jabber.ccc.org', + ), + array( + 'empty' => array('jabber'), + 'no_seperator' => array('jabber'), + 'no_user' => array('jabber'), + 'no_realm' => array('jabber'), + 'dot_realm' => array('jabber'), + '-realm' => array('jabber'), + 'realm-' => array('jabber'), + 'correct' => array('jabber'), + 'prohibited' => array('jabber'), + 'prohibited_char' => array('jabber'), + ), + array( + 'empty' => array(), + 'no_seperator' => array('WRONG_DATA'), + 'no_user' => array('WRONG_DATA'), + 'no_realm' => array('WRONG_DATA'), + 'dot_realm' => array('WRONG_DATA'), + '-realm' => array('WRONG_DATA'), + 'realm-' => array('WRONG_DATA'), + 'correct' => array(), + 'prohibited' => array('WRONG_DATA'), + 'prohibited_char' => array('WRONG_DATA'), + )); + } } diff --git a/tests/mock/cache.php b/tests/mock/cache.php index aa0db5ab20..acf4288319 100644 --- a/tests/mock/cache.php +++ b/tests/mock/cache.php @@ -74,6 +74,21 @@ class phpbb_mock_cache ); } + /** + * Obtain disallowed usernames. Input data via standard put method. + */ + public function obtain_disallowed_usernames() + { + if (($usernames = $this->get('_disallowed_usernames')) !== false) + { + return $usernames; + } + else + { + return array(); + } + } + public function set_bots($bots) { $this->data['_bots'] = $bots; diff --git a/tests/mock/user.php b/tests/mock/user.php index ec14ce430e..bd547b3973 100644 --- a/tests/mock/user.php +++ b/tests/mock/user.php @@ -33,4 +33,17 @@ class phpbb_mock_user { $this->options[$item] = $value; } + + public function check_ban($user_id = false, $user_ips = false, $user_email = false, $return = false) + { + $banned_users = $this->optionget('banned_users'); + foreach ($banned_users as $banned) + { + if ($banned == $user_id || $banned == $user_ips || $banned == $user_email) + { + return true; + } + } + return false; + } } From 6d5da402ecfe686a918608875eda8d0d817d4c07 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 30 May 2013 16:09:06 +0200 Subject: [PATCH 021/113] [ticket/11579] Remove unnecessary globals from validate_password() The globals $db and $user are not used in that function. PHPBB3-11579 --- phpBB/includes/functions_user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 2b26c6787c..ea8b0a4640 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -1554,7 +1554,7 @@ function validate_username($username, $allowed_username = false) */ function validate_password($password) { - global $config, $db, $user; + global $config; if ($password === '' || $config['pass_complex'] === 'PASS_TYPE_ANY') { From 33a0859f4ac3454c12dda651f708e16fc6c45adb Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 30 May 2013 20:34:21 +0200 Subject: [PATCH 022/113] [ticket/11579] Move tests into seperate files depending on needed fixture PHPBB3-11579 --- tests/functions/common_validate_data.php | 31 ++ tests/functions/fixtures/validate_email.xml | 23 + ...alidate_data.xml => validate_username.xml} | 21 - tests/functions/validate_data_simple_test.php | 252 +++++++++ tests/functions/validate_data_test.php | 478 ------------------ tests/functions/validate_email_test.php | 72 +++ tests/functions/validate_lang_iso_test.php | 56 ++ tests/functions/validate_username_test.php | 160 ++++++ 8 files changed, 594 insertions(+), 499 deletions(-) create mode 100644 tests/functions/common_validate_data.php create mode 100644 tests/functions/fixtures/validate_email.xml rename tests/functions/fixtures/{validate_data.xml => validate_username.xml} (63%) create mode 100644 tests/functions/validate_data_simple_test.php delete mode 100644 tests/functions/validate_data_test.php create mode 100644 tests/functions/validate_email_test.php create mode 100644 tests/functions/validate_lang_iso_test.php create mode 100644 tests/functions/validate_username_test.php diff --git a/tests/functions/common_validate_data.php b/tests/functions/common_validate_data.php new file mode 100644 index 0000000000..64c9499ac3 --- /dev/null +++ b/tests/functions/common_validate_data.php @@ -0,0 +1,31 @@ + array('string')) + * @param array $expected Array containing the expected results. Either + * an array containing the error message or the an empty + * array if input is correct + */ + public function validate_data_check($input, $validate_check, $expected) + { + foreach ($input as $key => $data) + { + $this->assertEquals($expected[$key], validate_data(array($data), array($validate_check[$key]))); + } + } +} diff --git a/tests/functions/fixtures/validate_email.xml b/tests/functions/fixtures/validate_email.xml new file mode 100644 index 0000000000..de7fce8a08 --- /dev/null +++ b/tests/functions/fixtures/validate_email.xml @@ -0,0 +1,23 @@ + + + + user_id + username + username_clean + user_permissions + user_sig + user_occ + user_interests + user_email_hash + + 1 + admin + admin + + + + + 143317126117 + +
      +
      diff --git a/tests/functions/fixtures/validate_data.xml b/tests/functions/fixtures/validate_username.xml similarity index 63% rename from tests/functions/fixtures/validate_data.xml rename to tests/functions/fixtures/validate_username.xml index 38ecae6ad2..fbe398469c 100644 --- a/tests/functions/fixtures/validate_data.xml +++ b/tests/functions/fixtures/validate_username.xml @@ -8,24 +8,6 @@ test123 - - lang_id - lang_iso - lang_local_name - lang_english_name - - 1 - en - English - English - - - 2 - cs - Čeština - Czech - -
      user_idusername @@ -34,7 +16,6 @@ user_siguser_occuser_interests - user_email_hash 1 admin @@ -43,7 +24,6 @@ - 143317126117 2 @@ -53,7 +33,6 @@ - 0
      diff --git a/tests/functions/validate_data_simple_test.php b/tests/functions/validate_data_simple_test.php new file mode 100644 index 0000000000..002b1f2298 --- /dev/null +++ b/tests/functions/validate_data_simple_test.php @@ -0,0 +1,252 @@ +common = new phpbb_functions_common_validate_data; + } + + public function test_validate_string() + { + $this->common->validate_data_check(array( + 'empty_opt' => '', + 'empty' => '', + 'foo' => 'foobar', + 'foo_minmax_correct' => 'foobar', + 'foo_minmax_short' => 'foobar', + 'foo_minmax_long' => 'foobar', + 'empty_short' => '', + 'empty_length_opt' => '', + ), + array( + 'empty_opt' => array('string', true), + 'empty' => array('string'), + 'foo' => array('string'), + 'foo_minmax_correct' => array('string', false, 2, 6), + 'foo_minmax_short' => array('string', false, 7, 9), + 'foo_minmax_long' => array('string', false, 2, 5), + 'empty_short' => array('string', false, 1, 6), + 'empty_length_opt' => array('string', true, 1, 6), + ), + array( + 'empty_opt' => array(), + 'empty' => array(), + 'foo' => array(), + 'foo_minmax_correct' => array(), + 'foo_minmax_short' => array('TOO_SHORT'), + 'foo_minmax_long' => array('TOO_LONG'), + 'empty_short' => array('TOO_SHORT'), + 'empty_length_opt' => array(), + )); + } + + public function test_validate_num() + { + $this->common->validate_data_check(array( + 'empty' => '', + 'zero' => 0, + 'five_minmax_correct' => 5, + 'five_minmax_short' => 5, + 'five_minmax_long' => 5, + 'string' => 'foobar', + ), + array( + 'empty' => array('num'), + 'zero' => array('num'), + 'five_minmax_correct' => array('num', false, 2, 6), + 'five_minmax_short' => array('num', false, 7, 10), + 'five_minmax_long' => array('num', false, 2, 3), + 'string' => array('num'), + ), + array( + 'empty' => array(), + 'zero' => array(), + 'five_minmax_correct' => array(), + 'five_minmax_short' => array('TOO_SMALL'), + 'five_minmax_long' => array('TOO_LARGE'), + 'string' => array(), + )); + } + + public function test_validate_date() + { + $this->common->validate_data_check(array( + 'empty' => '', + 'empty_opt' => '', + 'double_single' => '17-06-1990', + 'single_single' => '05-05-2009', + 'double_double' => '17-12-1990', + // Currently fails + //'zero_year' => '01-01-0000', + 'month_high' => '17-17-1990', + 'month_low' => '01-00-1990', + 'day_high' => '64-01-1990', + 'day_low' => '00-12-1990', + ), + array( + 'empty' => array('date'), + 'empty_opt' => array('date', true), + 'double_single' => array('date'), + 'single_single' => array('date'), + 'double_double' => array('date'), + // Currently fails + //'zero_year' => array('date'), + 'month_high' => array('date'), + 'month_low' => array('date'), + 'day_high' => array('date'), + 'day_low' => array('date'), + ), + array( + 'empty' => array('INVALID'), + 'empty_opt' => array(), + 'double_single' => array(), + 'single_single' => array(), + 'double_double' => array(), + // Currently fails + //'zero_year' => array(), + 'month_high' => array('INVALID'), + 'month_low' => array('INVALID'), + 'day_high' => array('INVALID'), + 'day_low' => array('INVALID'), + )); + } + + public function test_validate_match() + { + $this->common->validate_data_check(array( + 'empty_opt' => '', + 'empty_empty_match' => '', + 'foobar' => 'foobar', + 'foobar_fail' => 'foobar123', + ), + array( + 'empty_opt' => array('match', true, '/[a-z]$/'), + 'empty_empty_match' => array('match'), + 'foobar' => array('match', false, '/[a-z]$/'), + 'foobar_fail' => array('match', false, '/[a-z]$/'), + ), + array( + 'empty_opt' => array(), + 'empty_empty_match' => array(), + 'foobar' => array(), + 'foobar_fail' => array('WRONG_DATA'), + )); + } + + public function validate_password_data() + { + return array( + array('PASS_TYPE_ANY', array( + 'empty' => array(), + 'foobar_any' => array(), + 'foobar_mixed' => array(), + 'foobar_alpha' => array(), + 'foobar_symbol' => array(), + )), + array('PASS_TYPE_CASE', array( + 'empty' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_mixed' => array(), + 'foobar_alpha' => array(), + 'foobar_symbol' => array(), + )), + array('PASS_TYPE_ALPHA', array( + 'empty' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_mixed' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_symbol' => array(), + )), + array('PASS_TYPE_SYMBOL', array( + 'empty' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_mixed' => array('INVALID_CHARS'), + 'foobar_alpha' => array('INVALID_CHARS'), + 'foobar_symbol' => array(), + )), + ); + } + + /** + * @dataProvider validate_password_data + */ + public function test_validate_password($pass_complexity, $expected) + { + global $config; + + // Set complexity to mixed case letters, numbers and symbols + $config['pass_complex'] = $pass_complexity; + + $this->common->validate_data_check(array( + 'empty' => '', + 'foobar_any' => 'foobar', + 'foobar_mixed' => 'FooBar', + 'foobar_alpha' => 'F00bar', + 'foobar_symbol' => 'fooBar123*', + ), + array( + 'empty' => array('password'), + 'foobar_any' => array('password'), + 'foobar_mixed' => array('password'), + 'foobar_alpha' => array('password'), + 'foobar_symbol' => array('password'), + ), + $expected); + } + + public function test_validate_jabber() + { + $this->common->validate_data_check(array( + 'empty' => '', + 'no_seperator' => 'testjabber.ccc', + 'no_user' => '@jabber.ccc', + 'no_realm' => 'user@', + 'dot_realm' => 'user@.....', + '-realm' => 'user@-jabber.ccc', + 'realm-' => 'user@jabber.ccc-', + 'correct' => 'user@jabber.09A-z.org', + 'prohibited' => 'u@ser@jabber.ccc.org', + 'prohibited_char' => 'uer@jabber.ccc.org', + ), + array( + 'empty' => array('jabber'), + 'no_seperator' => array('jabber'), + 'no_user' => array('jabber'), + 'no_realm' => array('jabber'), + 'dot_realm' => array('jabber'), + '-realm' => array('jabber'), + 'realm-' => array('jabber'), + 'correct' => array('jabber'), + 'prohibited' => array('jabber'), + 'prohibited_char' => array('jabber'), + ), + array( + 'empty' => array(), + 'no_seperator' => array('WRONG_DATA'), + 'no_user' => array('WRONG_DATA'), + 'no_realm' => array('WRONG_DATA'), + 'dot_realm' => array('WRONG_DATA'), + '-realm' => array('WRONG_DATA'), + 'realm-' => array('WRONG_DATA'), + 'correct' => array(), + 'prohibited' => array('WRONG_DATA'), + 'prohibited_char' => array('WRONG_DATA'), + )); + } +} diff --git a/tests/functions/validate_data_test.php b/tests/functions/validate_data_test.php deleted file mode 100644 index ed91f782ba..0000000000 --- a/tests/functions/validate_data_test.php +++ /dev/null @@ -1,478 +0,0 @@ -createXMLDataSet(dirname(__FILE__) . '/fixtures/validate_data.xml'); - } - - protected function setUp() - { - parent::setUp(); - - $this->db = $this->new_dbal(); - $this->cache = new phpbb_mock_cache; - $this->user = new phpbb_mock_user; - } - - /** - * Test provided input data with supplied checks and compare to expected - * results - * - * @param array $input Input data with specific array keys that need to - * be matched by the ones in the other 2 params - * @param array $validate_check Array containing validate_data check - * settings, i.e. array('foobar' => array('string')) - * @param array $expected Array containing the expected results. Either - * an array containing the error message or the an empty - * array if input is correct - */ - public function validate_data_check($input, $validate_check, $expected) - { - foreach ($input as $key => $data) - { - $test = validate_data(array($data), array($validate_check[$key])); - if ($test != $expected[$key]) - { - var_dump($key, $data, $test, $expected[$key]); - } - $this->assertEquals($expected[$key], $test); - } - } - - public function test_validate_string() - { - $this->validate_data_check(array( - 'empty_opt' => '', - 'empty' => '', - 'foo' => 'foobar', - 'foo_minmax_correct' => 'foobar', - 'foo_minmax_short' => 'foobar', - 'foo_minmax_long' => 'foobar', - 'empty_short' => '', - 'empty_length_opt' => '', - ), - array( - 'empty_opt' => array('string', true), - 'empty' => array('string'), - 'foo' => array('string'), - 'foo_minmax_correct' => array('string', false, 2, 6), - 'foo_minmax_short' => array('string', false, 7, 9), - 'foo_minmax_long' => array('string', false, 2, 5), - 'empty_short' => array('string', false, 1, 6), - 'empty_length_opt' => array('string', true, 1, 6), - ), - array( - 'empty_opt' => array(), - 'empty' => array(), - 'foo' => array(), - 'foo_minmax_correct' => array(), - 'foo_minmax_short' => array('TOO_SHORT'), - 'foo_minmax_long' => array('TOO_LONG'), - 'empty_short' => array('TOO_SHORT'), - 'empty_length_opt' => array(), - )); - } - - public function test_validate_num() - { - $this->validate_data_check(array( - 'empty' => '', - 'zero' => 0, - 'five_minmax_correct' => 5, - 'five_minmax_short' => 5, - 'five_minmax_long' => 5, - 'string' => 'foobar', - ), - array( - 'empty' => array('num'), - 'zero' => array('num'), - 'five_minmax_correct' => array('num', false, 2, 6), - 'five_minmax_short' => array('num', false, 7, 10), - 'five_minmax_long' => array('num', false, 2, 3), - 'string' => array('num'), - ), - array( - 'empty' => array(), - 'zero' => array(), - 'five_minmax_correct' => array(), - 'five_minmax_short' => array('TOO_SMALL'), - 'five_minmax_long' => array('TOO_LARGE'), - 'string' => array(), - )); - } - - public function test_validate_date() - { - $this->validate_data_check(array( - 'empty' => '', - 'empty_opt' => '', - 'double_single' => '17-06-1990', - 'single_single' => '05-05-2009', - 'double_double' => '17-12-1990', - // Currently fails - //'zero_year' => '01-01-0000', - 'month_high' => '17-17-1990', - 'month_low' => '01-00-1990', - 'day_high' => '64-01-1990', - 'day_low' => '00-12-1990', - ), - array( - 'empty' => array('date'), - 'empty_opt' => array('date', true), - 'double_single' => array('date'), - 'single_single' => array('date'), - 'double_double' => array('date'), - // Currently fails - //'zero_year' => array('date'), - 'month_high' => array('date'), - 'month_low' => array('date'), - 'day_high' => array('date'), - 'day_low' => array('date'), - ), - array( - 'empty' => array('INVALID'), - 'empty_opt' => array(), - 'double_single' => array(), - 'single_single' => array(), - 'double_double' => array(), - // Currently fails - //'zero_year' => array(), - 'month_high' => array('INVALID'), - 'month_low' => array('INVALID'), - 'day_high' => array('INVALID'), - 'day_low' => array('INVALID'), - )); - } - - public function test_validate_match() - { - $this->validate_data_check(array( - 'empty_opt' => '', - 'empty_empty_match' => '', - 'foobar' => 'foobar', - 'foobar_fail' => 'foobar123', - ), - array( - 'empty_opt' => array('match', true, '/[a-z]$/'), - 'empty_empty_match' => array('match'), - 'foobar' => array('match', false, '/[a-z]$/'), - 'foobar_fail' => array('match', false, '/[a-z]$/'), - ), - array( - 'empty_opt' => array(), - 'empty_empty_match' => array(), - 'foobar' => array(), - 'foobar_fail' => array('WRONG_DATA'), - )); - } - - public function test_validate_lang_iso() - { - global $db; - - $db = $this->db; - - $this->validate_data_check(array( - 'empty' => '', - 'en' => 'en', - 'cs' => 'cs', - 'de' => 'de', - ), - array( - 'empty' => array('language_iso_name'), - 'en' => array('language_iso_name'), - 'cs' => array('language_iso_name'), - 'de' => array('language_iso_name'), - ), - array( - 'empty' => array('WRONG_DATA'), - 'en' => array(), - 'cs' => array(), - 'de' => array('WRONG_DATA'), - )); - } - - public function validate_username_data() - { - return array( - array('USERNAME_CHARS_ANY', array( - 'foobar_allow' => array(), - 'foobar_ascii' => array(), - 'foobar_any' => array(), - 'foobar_alpha' => array(), - 'foobar_alpha_spacers' => array(), - 'foobar_letter_num' => array(), - 'foobar_letter_num_sp' => array(), - 'foobar_quot' => array('INVALID_CHARS'), - 'barfoo_disallow' => array('USERNAME_DISALLOWED'), - 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('USERNAME_TAKEN') - )), - array('USERNAME_ALPHA_ONLY', array( - 'foobar_allow' => array(), - 'foobar_ascii' => array(), - 'foobar_any' => array('INVALID_CHARS'), - 'foobar_alpha' => array(), - 'foobar_alpha_spacers' => array('INVALID_CHARS'), - 'foobar_letter_num' => array(), - 'foobar_letter_num_sp' => array('INVALID_CHARS'), - 'foobar_quot' => array('INVALID_CHARS'), - 'barfoo_disallow' => array('USERNAME_DISALLOWED'), - 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('INVALID_CHARS') - )), - array('USERNAME_ALPHA_SPACERS', array( - 'foobar_allow' => array(), - 'foobar_ascii' => array(), - 'foobar_any' => array('INVALID_CHARS'), - 'foobar_alpha' => array(), - 'foobar_alpha_spacers' => array(), - 'foobar_letter_num' => array(), - 'foobar_letter_num_sp' => array('INVALID_CHARS'), - 'foobar_quot' => array('INVALID_CHARS'), - 'barfoo_disallow' => array('USERNAME_DISALLOWED'), - 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('USERNAME_TAKEN') - )), - array('USERNAME_LETTER_NUM', array( - 'foobar_allow' => array(), - 'foobar_ascii' => array(), - 'foobar_any' => array('INVALID_CHARS'), - 'foobar_alpha' => array(), - 'foobar_alpha_spacers' => array('INVALID_CHARS'), - 'foobar_letter_num' => array(), - 'foobar_letter_num_sp' => array('INVALID_CHARS'), - 'foobar_quot' => array('INVALID_CHARS'), - 'barfoo_disallow' => array('USERNAME_DISALLOWED'), - 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('INVALID_CHARS') - )), - array('USERNAME_LETTER_NUM_SPACERS', array( - 'foobar_allow' => array(), - 'foobar_ascii' => array(), - 'foobar_any' => array('INVALID_CHARS'), - 'foobar_alpha' => array(), - 'foobar_alpha_spacers' => array(), - 'foobar_letter_num' => array(), - 'foobar_letter_num_sp' => array(), - 'foobar_quot' => array('INVALID_CHARS'), - 'barfoo_disallow' => array('USERNAME_DISALLOWED'), - 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('USERNAME_TAKEN') - )), - array('USERNAME_ASCII', array( - 'foobar_allow' => array(), - 'foobar_ascii' => array(), - 'foobar_any' => array(), - 'foobar_alpha' => array(), - 'foobar_alpha_spacers' => array(), - 'foobar_letter_num' => array(), - 'foobar_letter_num_sp' => array('INVALID_CHARS'), - 'foobar_quot' => array('INVALID_CHARS'), - 'barfoo_disallow' => array('USERNAME_DISALLOWED'), - 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('USERNAME_TAKEN') - )), - ); - } - - /** - * @dataProvider validate_username_data - */ - public function test_validate_username($allow_name_chars, $expected) - { - global $cache, $config, $db; - - $db = $this->db; - $cache = $this->cache; - $cache->put('_disallowed_usernames', array('barfoo')); - - $config['allow_name_chars'] = $allow_name_chars; - - $this->validate_data_check(array( - 'foobar_allow' => 'foobar', - 'foobar_ascii' => 'foobar', - 'foobar_any' => 'f*~*^=oo_bar1', - 'foobar_alpha' => 'fo0Bar', - 'foobar_alpha_spacers' => 'Fo0-[B]_a+ R', - 'foobar_letter_num' => 'fo0Bar0', - 'foobar_letter_num_sp' => 'Fö0-[B]_a+ R', - 'foobar_quot' => '"foobar"', - 'barfoo_disallow' => 'barfoo', - 'admin_taken' => 'admin', - 'group_taken' => 'foobar_group', - ), - array( - 'foobar_allow' => array('username', 'foobar'), - 'foobar_ascii' => array('username'), - 'foobar_any' => array('username'), - 'foobar_alpha' => array('username'), - 'foobar_alpha_spacers' => array('username'), - 'foobar_letter_num' => array('username'), - 'foobar_letter_num_sp' => array('username'), - 'foobar_quot' => array('username'), - 'barfoo_disallow' => array('username'), - 'admin_taken' => array('username'), - 'group_taken' => array('username'), - ), - $expected); - } - - public function validate_password_data() - { - return array( - array('PASS_TYPE_ANY', array( - 'empty' => array(), - 'foobar_any' => array(), - 'foobar_mixed' => array(), - 'foobar_alpha' => array(), - 'foobar_symbol' => array(), - )), - array('PASS_TYPE_CASE', array( - 'empty' => array(), - 'foobar_any' => array('INVALID_CHARS'), - 'foobar_mixed' => array(), - 'foobar_alpha' => array(), - 'foobar_symbol' => array(), - )), - array('PASS_TYPE_ALPHA', array( - 'empty' => array(), - 'foobar_any' => array('INVALID_CHARS'), - 'foobar_mixed' => array('INVALID_CHARS'), - 'foobar_alpha' => array(), - 'foobar_symbol' => array(), - )), - array('PASS_TYPE_SYMBOL', array( - 'empty' => array(), - 'foobar_any' => array('INVALID_CHARS'), - 'foobar_mixed' => array('INVALID_CHARS'), - 'foobar_alpha' => array('INVALID_CHARS'), - 'foobar_symbol' => array(), - )), - ); - } - - /** - * @dataProvider validate_password_data - */ - public function test_validate_password($pass_complexity, $expected) - { - global $config; - - // Set complexity to mixed case letters, numbers and symbols - $config['pass_complex'] = $pass_complexity; - - $this->validate_data_check(array( - 'empty' => '', - 'foobar_any' => 'foobar', - 'foobar_mixed' => 'FooBar', - 'foobar_alpha' => 'F00bar', - 'foobar_symbol' => 'fooBar123*', - ), - array( - 'empty' => array('password'), - 'foobar_any' => array('password'), - 'foobar_mixed' => array('password'), - 'foobar_alpha' => array('password'), - 'foobar_symbol' => array('password'), - ), - $expected); - } - - public function test_validate_email() - { - global $config, $db, $user; - - $config['email_check_mx'] = true; - $db = $this->db; - $user = $this->user; - $user->optionset('banned_users', array('banned@example.com')); - - $this->validate_data_check(array( - 'empty' => '', - 'allowed' => 'foobar@example.com', - 'invalid' => 'fööbar@example.com', - 'valid_complex' => "'%$~test@example.com", - 'taken' => 'admin@example.com', - 'banned' => 'banned@example.com', - 'no_mx' => 'test@wwrrrhhghgghgh.ttv', - ), - array( - 'empty' => array('email'), - 'allowed' => array('email', 'foobar@example.com'), - 'invalid' => array('email'), - 'valid_complex' => array('email'), - 'taken' => array('email'), - 'banned' => array('email'), - 'no_mx' => array('email'), - ), - array( - 'empty' => array(), - 'allowed' => array(), - 'invalid' => array('EMAIL_INVALID'), - 'valid_complex' => array(), - 'taken' => array('EMAIL_TAKEN'), - 'banned' => array('EMAIL_BANNED'), - 'no_mx' => array('DOMAIN_NO_MX_RECORD'), - )); - } - - public function test_validate_jabber() - { - $this->validate_data_check(array( - 'empty' => '', - 'no_seperator' => 'testjabber.ccc', - 'no_user' => '@jabber.ccc', - 'no_realm' => 'user@', - 'dot_realm' => 'user@.....', - '-realm' => 'user@-jabber.ccc', - 'realm-' => 'user@jabber.ccc-', - 'correct' => 'user@jabber.09A-z.org', - 'prohibited' => 'u@ser@jabber.ccc.org', - 'prohibited_char' => 'uer@jabber.ccc.org', - ), - array( - 'empty' => array('jabber'), - 'no_seperator' => array('jabber'), - 'no_user' => array('jabber'), - 'no_realm' => array('jabber'), - 'dot_realm' => array('jabber'), - '-realm' => array('jabber'), - 'realm-' => array('jabber'), - 'correct' => array('jabber'), - 'prohibited' => array('jabber'), - 'prohibited_char' => array('jabber'), - ), - array( - 'empty' => array(), - 'no_seperator' => array('WRONG_DATA'), - 'no_user' => array('WRONG_DATA'), - 'no_realm' => array('WRONG_DATA'), - 'dot_realm' => array('WRONG_DATA'), - '-realm' => array('WRONG_DATA'), - 'realm-' => array('WRONG_DATA'), - 'correct' => array(), - 'prohibited' => array('WRONG_DATA'), - 'prohibited_char' => array('WRONG_DATA'), - )); - } -} diff --git a/tests/functions/validate_email_test.php b/tests/functions/validate_email_test.php new file mode 100644 index 0000000000..47aa37e11f --- /dev/null +++ b/tests/functions/validate_email_test.php @@ -0,0 +1,72 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/validate_email.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->db = $this->new_dbal(); + $this->user = new phpbb_mock_user; + $this->common = new phpbb_functions_common_validate_data; + } + + public function test_validate_email() + { + global $config, $db, $user; + + $config['email_check_mx'] = true; + $db = $this->db; + $user = $this->user; + $user->optionset('banned_users', array('banned@example.com')); + + $this->common->validate_data_check(array( + 'empty' => '', + 'allowed' => 'foobar@example.com', + 'invalid' => 'fööbar@example.com', + 'valid_complex' => "'%$~test@example.com", + 'taken' => 'admin@example.com', + 'banned' => 'banned@example.com', + 'no_mx' => 'test@wwrrrhhghgghgh.ttv', + ), + array( + 'empty' => array('email'), + 'allowed' => array('email', 'foobar@example.com'), + 'invalid' => array('email'), + 'valid_complex' => array('email'), + 'taken' => array('email'), + 'banned' => array('email'), + 'no_mx' => array('email'), + ), + array( + 'empty' => array(), + 'allowed' => array(), + 'invalid' => array('EMAIL_INVALID'), + 'valid_complex' => array(), + 'taken' => array('EMAIL_TAKEN'), + 'banned' => array('EMAIL_BANNED'), + 'no_mx' => array('DOMAIN_NO_MX_RECORD'), + )); + } +} diff --git a/tests/functions/validate_lang_iso_test.php b/tests/functions/validate_lang_iso_test.php new file mode 100644 index 0000000000..b8a1827432 --- /dev/null +++ b/tests/functions/validate_lang_iso_test.php @@ -0,0 +1,56 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/language_select.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->db = $this->new_dbal(); + $this->common = new phpbb_functions_common_validate_data; + } + + public function test_validate_lang_iso() + { + global $db; + + $db = $this->db; + + $this->common->validate_data_check(array( + 'empty' => '', + 'en' => 'en', + 'cs' => 'cs', + 'de' => 'de', + ), + array( + 'empty' => array('language_iso_name'), + 'en' => array('language_iso_name'), + 'cs' => array('language_iso_name'), + 'de' => array('language_iso_name'), + ), + array( + 'empty' => array('WRONG_DATA'), + 'en' => array(), + 'cs' => array(), + 'de' => array('WRONG_DATA'), + )); + } +} diff --git a/tests/functions/validate_username_test.php b/tests/functions/validate_username_test.php new file mode 100644 index 0000000000..656248cec3 --- /dev/null +++ b/tests/functions/validate_username_test.php @@ -0,0 +1,160 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/validate_username.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->db = $this->new_dbal(); + $this->cache = new phpbb_mock_cache; + $this->common = new phpbb_functions_common_validate_data; + } + + public function validate_username_data() + { + return array( + array('USERNAME_CHARS_ANY', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array(), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array(), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array(), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('USERNAME_TAKEN') + )), + array('USERNAME_ALPHA_ONLY', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array('INVALID_CHARS'), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array('INVALID_CHARS'), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('INVALID_CHARS') + )), + array('USERNAME_ALPHA_SPACERS', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array(), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array('INVALID_CHARS'), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('USERNAME_TAKEN') + )), + array('USERNAME_LETTER_NUM', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array('INVALID_CHARS'), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array('INVALID_CHARS'), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('INVALID_CHARS') + )), + array('USERNAME_LETTER_NUM_SPACERS', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array(), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array(), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('USERNAME_TAKEN') + )), + array('USERNAME_ASCII', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array(), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array(), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array('INVALID_CHARS'), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('USERNAME_TAKEN') + )), + ); + } + + /** + * @dataProvider validate_username_data + */ + public function test_validate_username($allow_name_chars, $expected) + { + global $cache, $config, $db; + + $db = $this->db; + $cache = $this->cache; + $cache->put('_disallowed_usernames', array('barfoo')); + + $config['allow_name_chars'] = $allow_name_chars; + + $this->common->validate_data_check(array( + 'foobar_allow' => 'foobar', + 'foobar_ascii' => 'foobar', + 'foobar_any' => 'f*~*^=oo_bar1', + 'foobar_alpha' => 'fo0Bar', + 'foobar_alpha_spacers' => 'Fo0-[B]_a+ R', + 'foobar_letter_num' => 'fo0Bar0', + 'foobar_letter_num_sp' => 'Fö0-[B]_a+ R', + 'foobar_quot' => '"foobar"', + 'barfoo_disallow' => 'barfoo', + 'admin_taken' => 'admin', + 'group_taken' => 'foobar_group', + ), + array( + 'foobar_allow' => array('username', 'foobar'), + 'foobar_ascii' => array('username'), + 'foobar_any' => array('username'), + 'foobar_alpha' => array('username'), + 'foobar_alpha_spacers' => array('username'), + 'foobar_letter_num' => array('username'), + 'foobar_letter_num_sp' => array('username'), + 'foobar_quot' => array('username'), + 'barfoo_disallow' => array('username'), + 'admin_taken' => array('username'), + 'group_taken' => array('username'), + ), + $expected); + } +} From b7b81f64316a900d6de308d4b65f89b7b4b58e2f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 31 May 2013 16:16:41 +0200 Subject: [PATCH 023/113] [ticket/11568] Use static calls for static methods PHPBB3-11568 --- tests/functional/auth_test.php | 8 ++++---- tests/functional/browse_test.php | 6 +++--- tests/functional/common_groups_test.php | 4 ++-- tests/functional/posting_test.php | 14 +++++++------- .../test_framework/phpbb_functional_test_case.php | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php index a0c909e798..afb4f15fc2 100644 --- a/tests/functional/auth_test.php +++ b/tests/functional/auth_test.php @@ -17,7 +17,7 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case $this->login(); // check for logout link - $crawler = $this->request('GET', 'index.php'); + $crawler = self::request('GET', 'index.php'); $this->assertContains($this->lang('LOGOUT_USER', 'admin'), $crawler->filter('.navbar')->text()); } @@ -25,7 +25,7 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case { $this->create_user('anothertestuser'); $this->login('anothertestuser'); - $crawler = $this->request('GET', 'index.php'); + $crawler = self::request('GET', 'index.php'); $this->assertContains('anothertestuser', $crawler->filter('.icon-logout')->text()); } @@ -38,11 +38,11 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case $this->add_lang('ucp'); // logout - $crawler = $this->request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); + $crawler = self::request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); $this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text()); // look for a register link, which should be visible only when logged out - $crawler = $this->request('GET', 'index.php'); + $crawler = self::request('GET', 'index.php'); $this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text()); } } diff --git a/tests/functional/browse_test.php b/tests/functional/browse_test.php index 26c18c4c1f..18a2ad9464 100644 --- a/tests/functional/browse_test.php +++ b/tests/functional/browse_test.php @@ -14,19 +14,19 @@ class phpbb_functional_browse_test extends phpbb_functional_test_case { public function test_index() { - $crawler = $this->request('GET', 'index.php'); + $crawler = self::request('GET', 'index.php'); $this->assertGreaterThan(0, $crawler->filter('.topiclist')->count()); } public function test_viewforum() { - $crawler = $this->request('GET', 'viewforum.php?f=2'); + $crawler = self::request('GET', 'viewforum.php?f=2'); $this->assertGreaterThan(0, $crawler->filter('.topiclist')->count()); } public function test_viewtopic() { - $crawler = $this->request('GET', 'viewtopic.php?t=1'); + $crawler = self::request('GET', 'viewtopic.php?t=1'); $this->assertGreaterThan(0, $crawler->filter('.postbody')->count()); } } diff --git a/tests/functional/common_groups_test.php b/tests/functional/common_groups_test.php index 6e1f1afdce..7c88ec900d 100644 --- a/tests/functional/common_groups_test.php +++ b/tests/functional/common_groups_test.php @@ -35,10 +35,10 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test $this->add_lang(array('ucp', 'acp/groups')); // Manage Administrators group - $crawler = $this->request('GET', $this->get_url() . '&g=5&sid=' . $this->sid); + $crawler = self::request('GET', $this->get_url() . '&g=5&sid=' . $this->sid); $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); $form['group_colour']->setValue($input); - $crawler = $this->submit($form); + $crawler = self::submit($form); $this->assertContains($this->lang($expected), $crawler->text()); } } diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index 5cf7559245..9bcfcc2fda 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -19,17 +19,17 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case // Test creating topic $post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.'); - $crawler = $this->request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); + $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); $this->assertContains('This is a test topic posted by the testing framework.', $crawler->filter('html')->text()); // Test creating a reply $post2 = $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post posted by the testing framework.'); - $crawler = $this->request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); + $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); // Test quoting a message - $crawler = $this->request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}"); + $crawler = self::request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}"); $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); } @@ -54,7 +54,7 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case 'post' => true, ), $additional_form_data); - return $this->submit_post($posting_url, 'POST_TOPIC', $form_data); + return self::submit_post($posting_url, 'POST_TOPIC', $form_data); } /** @@ -78,7 +78,7 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case 'post' => true, ), $additional_form_data); - return $this->submit_post($posting_url, 'POST_REPLY', $form_data); + return self::submit_post($posting_url, 'POST_REPLY', $form_data); } /** @@ -93,7 +93,7 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case { $this->add_lang('posting'); - $crawler = $this->request('GET', $posting_url); + $crawler = self::request('GET', $posting_url); $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); $hidden_fields = array( @@ -117,7 +117,7 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case // I use a request because the form submission method does not allow you to send data that is not // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) // Instead, I send it as a request with the submit button "post" set to true. - $crawler = $this->request('POST', $posting_url, $form_data); + $crawler = self::request('POST', $posting_url, $form_data); $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); $url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri(); diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 04a43182ae..a0dceb152b 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -344,11 +344,11 @@ class phpbb_functional_test_case extends phpbb_test_case { $this->add_lang('ucp'); - $crawler = $this->request('GET', 'ucp.php'); + $crawler = self::request('GET', 'ucp.php'); $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text()); $form = $crawler->selectButton($this->lang('LOGIN'))->form(); - $crawler = $this->submit($form, array('username' => $username, 'password' => $username . $username)); + $crawler = self::submit($form, array('username' => $username, 'password' => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); @@ -379,7 +379,7 @@ class phpbb_functional_test_case extends phpbb_test_case return; } - $crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid); + $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid); $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), $crawler->filter('html')->text()); $form = $crawler->selectButton($this->lang('LOGIN'))->form(); @@ -388,7 +388,7 @@ class phpbb_functional_test_case extends phpbb_test_case { if (strpos($field, 'password_') === 0) { - $crawler = $this->submit($form, array('username' => $username, $field => $username . $username)); + $crawler = self::submit($form, array('username' => $username, $field => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); From b2be82cd57fd14e354d9e9c06b0324db74b754cf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 31 May 2013 16:19:19 +0200 Subject: [PATCH 024/113] [ticket/11568] Invert logic for asserting the response PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index a0dceb152b..f1d282311f 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -83,11 +83,11 @@ class phpbb_functional_test_case extends phpbb_test_case * @param bool $skip_assert_response_success Should we skip the basic response assertions? * @return Symfony\Component\DomCrawler\Crawler */ - static public function request($method, $path, $form_data = array(), $skip_assert_response_success = false) + static public function request($method, $path, $form_data = array(), $assert_response_success = true) { $crawler = self::$client->request($method, self::$root_url . $path, $form_data); - if (!$skip_assert_response_success) + if ($assert_response_success) { self::assert_response_success(); } @@ -103,11 +103,11 @@ class phpbb_functional_test_case extends phpbb_test_case * @param bool $skip_assert_response_success Should we skip the basic response assertions? * @return Symfony\Component\DomCrawler\Crawler */ - static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $skip_assert_response_success = false) + static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $assert_response_success = true) { $crawler = self::$client->submit($form, $values); - if (!$skip_assert_response_success) + if ($assert_response_success) { self::assert_response_success(); } From 09a3877ae4c5bda66f22d89408b589ea8b56f380 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 31 May 2013 16:20:20 +0200 Subject: [PATCH 025/113] [ticket/11568] Add comma at end of array key-value couple PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index f1d282311f..5416125f42 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -202,7 +202,7 @@ class phpbb_functional_test_case extends phpbb_test_case self::$client->setClient(new Guzzle\Http\Client('', array( Guzzle\Http\Client::DISABLE_REDIRECTS => true, 'curl.options' => array( - CURLOPT_TIMEOUT => 120 + CURLOPT_TIMEOUT => 120, ), ))); From 6af5262fcccae3f3e651348a20dbbd8a78e191aa Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 31 May 2013 16:27:52 +0200 Subject: [PATCH 026/113] [ticket/11568] Split status code and html debug assertion into two methods PHPBB3-11568 --- .../phpbb_functional_test_case.php | 48 ++++++++++++------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 5416125f42..651ab013c7 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -80,16 +80,16 @@ class phpbb_functional_test_case extends phpbb_test_case * @param string $method HTTP Method * @param string $path Page path, relative from phpBB root path * @param array $form_data An array of form field values - * @param bool $skip_assert_response_success Should we skip the basic response assertions? + * @param bool $assert_response_html Should we perform standard assertions for a normal html page * @return Symfony\Component\DomCrawler\Crawler */ - static public function request($method, $path, $form_data = array(), $assert_response_success = true) + static public function request($method, $path, $form_data = array(), $assert_response_html = true) { $crawler = self::$client->request($method, self::$root_url . $path, $form_data); - if ($assert_response_success) + if ($assert_response_html) { - self::assert_response_success(); + self::assert_response_html(); } return $crawler; @@ -100,16 +100,16 @@ class phpbb_functional_test_case extends phpbb_test_case * * @param Symfony\Component\DomCrawler\Form $form A Form instance * @param array $values An array of form field values - * @param bool $skip_assert_response_success Should we skip the basic response assertions? + * @param bool $assert_response_html Should we perform standard assertions for a normal html page * @return Symfony\Component\DomCrawler\Crawler */ - static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $assert_response_success = true) + static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $assert_response_html = true) { $crawler = self::$client->submit($form, $values); - if ($assert_response_success) + if ($assert_response_html) { - self::assert_response_success(); + self::assert_response_html(); } return $crawler; @@ -349,7 +349,6 @@ class phpbb_functional_test_case extends phpbb_test_case $form = $crawler->selectButton($this->lang('LOGIN'))->form(); $crawler = self::submit($form, array('username' => $username, 'password' => $username . $username)); - $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); $cookies = self::$cookieJar->all(); @@ -389,7 +388,6 @@ class phpbb_functional_test_case extends phpbb_test_case if (strpos($field, 'password_') === 0) { $crawler = self::submit($form, array('username' => $username, $field => $username . $username)); - $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); $cookies = self::$cookieJar->all(); @@ -445,23 +443,37 @@ class phpbb_functional_test_case extends phpbb_test_case return call_user_func_array('sprintf', $args); } + /** + * Perform some basic assertions for the page + * + * Checks for debug/error output before the actual page content and the status code + * + * @param mixed $status_code Expected status code, false to disable check + * @return null + */ + static public function assert_response_html($status_code = 200) + { + if ($status_code !== false) + { + self::assert_response_status_code($status_code); + } + + // Any output before the doc type means there was an error + $content = self::$client->getResponse()->getContent(); + self::assertStringStartsWith('getResponse()->getStatus()); - $content = self::$client->getResponse()->getContent(); - - // Any output before the doc type means there was an error - if (strpos($content, ' Date: Sat, 1 Jun 2013 04:09:33 +0200 Subject: [PATCH 027/113] [ticket/11583] Allow FULLTEXT indexes on InnoDB when on MySQL 5.6.4 or higher. PHPBB3-11583 --- phpBB/includes/search/fulltext_mysql.php | 9 ++++++++- phpBB/language/en/acp/search.php | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index bd4c003397..a2211bbe9b 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -86,7 +86,14 @@ class fulltext_mysql extends search_backend $engine = $info['Type']; } - if ($engine != 'MyISAM') + $fulltext_supported = + $engine === 'MyISAM' || + // FULLTEXT is supported on InnoDB since MySQL 5.6.4 according to + // http://dev.mysql.com/doc/refman/5.6/en/innodb-storage-engine.html + $engine === 'InnoDB' && + phpbb_version_compare($db->sql_server_info(true), '5.6.4', '>='); + + if (!$fulltext_supported) { return $user->lang['FULLTEXT_MYSQL_NOT_MYISAM']; } diff --git a/phpBB/language/en/acp/search.php b/phpBB/language/en/acp/search.php index a7d687d7c2..ded5584a7e 100644 --- a/phpBB/language/en/acp/search.php +++ b/phpBB/language/en/acp/search.php @@ -53,7 +53,7 @@ $lang = array_merge($lang, array( 'DELETING_INDEX_IN_PROGRESS_EXPLAIN' => 'The search backend is currently cleaning its index. This can take a few minutes.', 'FULLTEXT_MYSQL_INCOMPATIBLE_VERSION' => 'The MySQL fulltext backend can only be used with MySQL4 and above.', - 'FULLTEXT_MYSQL_NOT_MYISAM' => 'MySQL fulltext indexes can only be used with MyISAM tables.', + 'FULLTEXT_MYSQL_NOT_MYISAM' => 'MySQL fulltext indexes can only be used with MyISAM or InnoDB tables. MySQL 5.6.4 or later is required for fulltext indexes on InnoDB tables.', 'FULLTEXT_MYSQL_TOTAL_POSTS' => 'Total number of indexed posts', 'FULLTEXT_MYSQL_MBSTRING' => 'Support for non-latin UTF-8 characters using mbstring:', 'FULLTEXT_MYSQL_PCRE' => 'Support for non-latin UTF-8 characters using PCRE:', From 0eae9eb75d4a66d0064df7095aacb8907cde3572 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 3 Jun 2013 10:54:16 +0200 Subject: [PATCH 028/113] [ticket/10840] Add check_form_key to acp_groups.php PHPBB3-10840 --- phpBB/includes/acp/acp_groups.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 83c355540e..9b9ea38e07 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -80,6 +80,11 @@ class acp_groups case 'approve': case 'demote': case 'promote': + if (!check_form_key($form_key)) + { + trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); + } + if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); @@ -252,6 +257,11 @@ class acp_groups break; case 'addusers': + if (!check_form_key($form_key)) + { + trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); + } + if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); From cb62b37bce2201ec1f0dbdbaa5945f285ad7d6d1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 3 Jun 2013 11:06:12 +0200 Subject: [PATCH 029/113] [ticket/11122] Remove Oleg and igorw from active authors PHPBB3-11122 --- phpBB/docs/AUTHORS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/docs/AUTHORS b/phpBB/docs/AUTHORS index fcef26daa1..a4d421b6ce 100644 --- a/phpBB/docs/AUTHORS +++ b/phpBB/docs/AUTHORS @@ -24,10 +24,8 @@ phpBB Lead Developer: naderman (Nils Adermann) phpBB Developers: bantu (Andreas Fischer) EXreaction (Nathan Guse) - igorw (Igor Wiedler) imkingdavid (David King) nickvergessen (Joas Schilling) - Oleg (Oleg Pudeyev) Contributions by: leviatan21 (Gabriel Vazquez) Raimon (Raimon Meuldijk) @@ -53,6 +51,8 @@ phpBB Developers: A_Jelly_Doughnut (Josh Woody) [01/2010 - 11/2010] dhn (Dominik Dröscher) [05/2007 - 01/2011] GrahamJE (Graham Eames) [09/2005 - 11/2006] kellanved (Henry Sudhof) [04/2007 - 03/2011] + igorw (Igor Wiedler) [08/2010 - 02/2013] + Oleg (Oleg Pudeyev) [01/2011 - 05/2013] rxu (Ruslan Uzdenov) [04/2010 - 12/2012] TerraFrost (Jim Wigginton) [04/2009 - 01/2011] ToonArmy (Chris Smith) [06/2008 - 11/2011] From 323bfbc78f379624f133e0027d9dfef8513c8cf5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 3 Jun 2013 11:08:50 +0200 Subject: [PATCH 030/113] [ticket/11122] Add dhruv to active authors PHPBB3-11122 --- phpBB/docs/AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/docs/AUTHORS b/phpBB/docs/AUTHORS index a4d421b6ce..5995bd2ab4 100644 --- a/phpBB/docs/AUTHORS +++ b/phpBB/docs/AUTHORS @@ -24,6 +24,7 @@ phpBB Lead Developer: naderman (Nils Adermann) phpBB Developers: bantu (Andreas Fischer) EXreaction (Nathan Guse) + dhruv.goel92 (Dhruv Goel) imkingdavid (David King) nickvergessen (Joas Schilling) From 81140ec8877236050b822517f735b49503bcd44d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 3 Jun 2013 12:15:23 +0200 Subject: [PATCH 031/113] [ticket/8319] Prepend Board URL to LOCAL_URL links to prevent abuse The description says: "The URL must be relative to the topic page and cannot contain a server name or protocol." We now enforce this and will add a new token with the current behaviour back. PHPBB3-8319 --- phpBB/includes/acp/acp_bbcodes.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index 0644b38eb1..2cb1390c8e 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -427,7 +427,15 @@ class acp_bbcodes $fp_replace = str_replace($token, $replace, $fp_replace); $sp_match = str_replace(preg_quote($token, '!'), $sp_tokens[$token_type], $sp_match); - $sp_replace = str_replace($token, '${' . ($n + 1) . '}', $sp_replace); + if ($token_type === 'LOCAL_URL') + { + // Prepend the board url to local relative links + $sp_replace = str_replace($token, generate_board_url() . '/' . '${' . ($n + 1) . '}', $sp_replace); + } + else + { + $sp_replace = str_replace($token, '${' . ($n + 1) . '}', $sp_replace); + } } $fp_match = '!' . $fp_match . '!' . $modifiers; From c0e0c13cf17bac9256e3acb1ea2d67134d6122dd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 3 Jun 2013 11:57:40 +0200 Subject: [PATCH 032/113] [ticket/8319] Add new token RELATIVE_URL to allow foreign relative URL parts PHPBB3-8319 --- phpBB/includes/acp/acp_bbcodes.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index 2cb1390c8e..02ec8af5b9 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -345,6 +345,9 @@ class acp_bbcodes 'LOCAL_URL' => array( '!(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')!e' => "\$this->bbcode_specialchars('$1')" ), + 'RELATIVE_URL' => array( + '!(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')!e' => "\$this->bbcode_specialchars('$1')" + ), 'EMAIL' => array( '!(' . get_preg_expression('email') . ')!ie' => "\$this->bbcode_specialchars('$1')" ), @@ -371,6 +374,7 @@ class acp_bbcodes $sp_tokens = array( 'URL' => '(?i)((?:' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('url')) . ')|(?:' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('www_url')) . '))(?-i)', 'LOCAL_URL' => '(?i)(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')(?-i)', + 'RELATIVE_URL' => '(?i)(' . str_replace(array('!', '\#'), array('\!', '#'), get_preg_expression('relative_url')) . ')(?-i)', 'EMAIL' => '(' . get_preg_expression('email') . ')', 'TEXT' => '(.*?)', 'SIMPLETEXT' => '([a-zA-Z0-9-+.,_ ]+)', From 24bfaa13270bbdeca1e00c95b025b3fd42742633 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 3 Jun 2013 12:37:57 +0200 Subject: [PATCH 033/113] [ticket/8319] Update BBCodes that currently use the LOCAL_URL tag on update To fix http://tracker.phpbb.com/browse/PHPBB3-8319 we changed the second_pass_replace value, so that needs updating for existing ones. PHPBB3-8319 --- phpBB/install/database_update.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 8aa62af7e1..a0ca05a129 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2204,6 +2204,36 @@ function change_database_data(&$no_updates, $version) _sql($sql, $errored, $error_ary); } + /** + * Update BBCodes that currently use the LOCAL_URL tag + * + * To fix http://tracker.phpbb.com/browse/PHPBB3-8319 we changed + * the second_pass_replace value, so that needs updating for existing ones + */ + $sql = 'SELECT * + FROM ' . BBCODES_TABLE . ' + WHERE bbcode_match ' . $db->sql_like_expression($db->any_char . 'LOCAL_URL' . $db->any_char); + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + if (!class_exists('acp_bbcodes')) + { + phpbb_require_updated('includes/acp/acp_bbcodes.' . $phpEx); + } + $bbcode_match = $row['bbcode_match']; + $bbcode_tpl = $row['bbcode_tpl']; + + $acp_bbcodes = new acp_bbcodes(); + $sql_ary = $acp_bbcodes->build_regexp($bbcode_match, $bbcode_tpl); + + $sql = 'UPDATE ' . BBCODES_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE bbcode_id = ' . (int) $row['bbcode_id']; + $db->sql_query($sql); + } + $db->sql_freeresult($result); + $no_updates = false; break; } From 6206d4aa4ea08df513154d8b87d35785f69a9f2a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 3 Jun 2013 12:35:57 +0200 Subject: [PATCH 034/113] [ticket/8319] Add explanation for RELATIVE_URL and update LOCAL_URL The explanation now states that links are prefixed with the board URL. PHPBB3-8319 --- phpBB/includes/acp/acp_bbcodes.php | 4 ++-- phpBB/language/en/acp/posting.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index 02ec8af5b9..ead716b300 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -113,8 +113,8 @@ class acp_bbcodes { $template->assign_block_vars('token', array( 'TOKEN' => '{' . $token . '}', - 'EXPLAIN' => $token_explain) - ); + 'EXPLAIN' => ($token === 'LOCAL_URL') ? sprintf($token_explain, generate_board_url() . '/') : $token_explain, + )); } return; diff --git a/phpBB/language/en/acp/posting.php b/phpBB/language/en/acp/posting.php index 9719287c2a..9232be661b 100644 --- a/phpBB/language/en/acp/posting.php +++ b/phpBB/language/en/acp/posting.php @@ -83,7 +83,8 @@ $lang = array_merge($lang, array( 'NUMBER' => 'Any series of digits', 'EMAIL' => 'A valid e-mail address', 'URL' => 'A valid URL using any protocol (http, ftp, etc… cannot be used for javascript exploits). If none is given, “http://” is prefixed to the string.', - 'LOCAL_URL' => 'A local URL. The URL must be relative to the topic page and cannot contain a server name or protocol.', + 'LOCAL_URL' => 'A local URL. The URL must be relative to the topic page and cannot contain a server name or protocol, as links are prefixed with “%s”', + 'RELATIVE_URL' => 'A relative URL. You can use this to match parts of a URL, but be careful: a full URL is a valid relative URL. When you want to use relative URLs of your board, use the LOCAL_URL token.', 'COLOR' => 'A HTML colour, can be either in the numeric form #FF1234 or a CSS colour keyword such as fuchsia or InactiveBorder' ) )); From d925c8d0daca58ce6f2a7b327e496c072c8a9fc8 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 3 Jun 2013 15:16:57 +0200 Subject: [PATCH 035/113] [ticket/11583] Use a new lang key instead of giving the old one a new meaning. PHPBB3-11583 --- phpBB/includes/search/fulltext_mysql.php | 2 +- phpBB/language/en/acp/search.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index a2211bbe9b..f28b8885e7 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -95,7 +95,7 @@ class fulltext_mysql extends search_backend if (!$fulltext_supported) { - return $user->lang['FULLTEXT_MYSQL_NOT_MYISAM']; + return $user->lang['FULLTEXT_MYSQL_NOT_SUPPORTED']; } $sql = 'SHOW VARIABLES diff --git a/phpBB/language/en/acp/search.php b/phpBB/language/en/acp/search.php index ded5584a7e..79ac75c833 100644 --- a/phpBB/language/en/acp/search.php +++ b/phpBB/language/en/acp/search.php @@ -53,7 +53,7 @@ $lang = array_merge($lang, array( 'DELETING_INDEX_IN_PROGRESS_EXPLAIN' => 'The search backend is currently cleaning its index. This can take a few minutes.', 'FULLTEXT_MYSQL_INCOMPATIBLE_VERSION' => 'The MySQL fulltext backend can only be used with MySQL4 and above.', - 'FULLTEXT_MYSQL_NOT_MYISAM' => 'MySQL fulltext indexes can only be used with MyISAM or InnoDB tables. MySQL 5.6.4 or later is required for fulltext indexes on InnoDB tables.', + 'FULLTEXT_MYSQL_NOT_SUPPORTED' => 'MySQL fulltext indexes can only be used with MyISAM or InnoDB tables. MySQL 5.6.4 or later is required for fulltext indexes on InnoDB tables.', 'FULLTEXT_MYSQL_TOTAL_POSTS' => 'Total number of indexed posts', 'FULLTEXT_MYSQL_MBSTRING' => 'Support for non-latin UTF-8 characters using mbstring:', 'FULLTEXT_MYSQL_PCRE' => 'Support for non-latin UTF-8 characters using PCRE:', From 3487b70cc066f090c55990a9082ed9684d438147 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 3 Jun 2013 16:06:11 +0200 Subject: [PATCH 036/113] [ticket/11579] Use test case helper class and use assert prefix for method PHPBB3-11579 --- ...date_data.php => validate_data_helper.php} | 19 ++- tests/functions/validate_data_simple_test.php | 119 +++++++++--------- tests/functions/validate_email_test.php | 26 ++-- tests/functions/validate_lang_iso_test.php | 20 +-- tests/functions/validate_username_test.php | 11 +- 5 files changed, 100 insertions(+), 95 deletions(-) rename tests/functions/{common_validate_data.php => validate_data_helper.php} (65%) diff --git a/tests/functions/common_validate_data.php b/tests/functions/validate_data_helper.php similarity index 65% rename from tests/functions/common_validate_data.php rename to tests/functions/validate_data_helper.php index 64c9499ac3..b8e8bfded3 100644 --- a/tests/functions/common_validate_data.php +++ b/tests/functions/validate_data_helper.php @@ -7,25 +7,32 @@ * */ -class phpbb_functions_common_validate_data extends phpbb_test_case +class phpbb_functions_validate_data_helper extends PHPUnit_Framework_TestCase { + protected $test_case; + + public function __construct($test_case) + { + $this->test_case = $test_case; + } + /** * Test provided input data with supplied checks and compare to expected * results * + * @param array $expected Array containing the expected results. Either + * an array containing the error message or the an empty + * array if input is correct * @param array $input Input data with specific array keys that need to * be matched by the ones in the other 2 params * @param array $validate_check Array containing validate_data check * settings, i.e. array('foobar' => array('string')) - * @param array $expected Array containing the expected results. Either - * an array containing the error message or the an empty - * array if input is correct */ - public function validate_data_check($input, $validate_check, $expected) + public function assert_validate_data($expected, $input, $validate_check) { foreach ($input as $key => $data) { - $this->assertEquals($expected[$key], validate_data(array($data), array($validate_check[$key]))); + $this->test_case->assertEquals($expected[$key], validate_data(array($data), array($validate_check[$key]))); } } } diff --git a/tests/functions/validate_data_simple_test.php b/tests/functions/validate_data_simple_test.php index 002b1f2298..db4f218eed 100644 --- a/tests/functions/validate_data_simple_test.php +++ b/tests/functions/validate_data_simple_test.php @@ -9,22 +9,32 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; -require_once dirname(__FILE__) . '/common_validate_data.php'; +require_once dirname(__FILE__) . '/validate_data_helper.php'; class phpbb_functions_validate_data_simple_test extends phpbb_test_case { - protected $common; + protected $helper; protected function setUp() { parent::setUp(); - $this->common = new phpbb_functions_common_validate_data; + $this->helper = new phpbb_functions_validate_data_helper($this); } public function test_validate_string() { - $this->common->validate_data_check(array( + $this->helper->assert_validate_data(array( + 'empty_opt' => array(), + 'empty' => array(), + 'foo' => array(), + 'foo_minmax_correct' => array(), + 'foo_minmax_short' => array('TOO_SHORT'), + 'foo_minmax_long' => array('TOO_LONG'), + 'empty_short' => array('TOO_SHORT'), + 'empty_length_opt' => array(), + ), + array( 'empty_opt' => '', 'empty' => '', 'foo' => 'foobar', @@ -43,22 +53,20 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case 'foo_minmax_long' => array('string', false, 2, 5), 'empty_short' => array('string', false, 1, 6), 'empty_length_opt' => array('string', true, 1, 6), - ), - array( - 'empty_opt' => array(), - 'empty' => array(), - 'foo' => array(), - 'foo_minmax_correct' => array(), - 'foo_minmax_short' => array('TOO_SHORT'), - 'foo_minmax_long' => array('TOO_LONG'), - 'empty_short' => array('TOO_SHORT'), - 'empty_length_opt' => array(), )); } public function test_validate_num() { - $this->common->validate_data_check(array( + $this->helper->assert_validate_data(array( + 'empty' => array(), + 'zero' => array(), + 'five_minmax_correct' => array(), + 'five_minmax_short' => array('TOO_SMALL'), + 'five_minmax_long' => array('TOO_LARGE'), + 'string' => array(), + ), + array( 'empty' => '', 'zero' => 0, 'five_minmax_correct' => 5, @@ -73,20 +81,25 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case 'five_minmax_short' => array('num', false, 7, 10), 'five_minmax_long' => array('num', false, 2, 3), 'string' => array('num'), - ), - array( - 'empty' => array(), - 'zero' => array(), - 'five_minmax_correct' => array(), - 'five_minmax_short' => array('TOO_SMALL'), - 'five_minmax_long' => array('TOO_LARGE'), - 'string' => array(), )); } public function test_validate_date() { - $this->common->validate_data_check(array( + $this->helper->assert_validate_data(array( + 'empty' => array('INVALID'), + 'empty_opt' => array(), + 'double_single' => array(), + 'single_single' => array(), + 'double_double' => array(), + // Currently fails + //'zero_year' => array(), + 'month_high' => array('INVALID'), + 'month_low' => array('INVALID'), + 'day_high' => array('INVALID'), + 'day_low' => array('INVALID'), + ), + array( 'empty' => '', 'empty_opt' => '', 'double_single' => '17-06-1990', @@ -111,25 +124,18 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case 'month_low' => array('date'), 'day_high' => array('date'), 'day_low' => array('date'), - ), - array( - 'empty' => array('INVALID'), - 'empty_opt' => array(), - 'double_single' => array(), - 'single_single' => array(), - 'double_double' => array(), - // Currently fails - //'zero_year' => array(), - 'month_high' => array('INVALID'), - 'month_low' => array('INVALID'), - 'day_high' => array('INVALID'), - 'day_low' => array('INVALID'), )); } public function test_validate_match() { - $this->common->validate_data_check(array( + $this->helper->assert_validate_data(array( + 'empty_opt' => array(), + 'empty_empty_match' => array(), + 'foobar' => array(), + 'foobar_fail' => array('WRONG_DATA'), + ), + array( 'empty_opt' => '', 'empty_empty_match' => '', 'foobar' => 'foobar', @@ -140,12 +146,6 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case 'empty_empty_match' => array('match'), 'foobar' => array('match', false, '/[a-z]$/'), 'foobar_fail' => array('match', false, '/[a-z]$/'), - ), - array( - 'empty_opt' => array(), - 'empty_empty_match' => array(), - 'foobar' => array(), - 'foobar_fail' => array('WRONG_DATA'), )); } @@ -193,7 +193,7 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case // Set complexity to mixed case letters, numbers and symbols $config['pass_complex'] = $pass_complexity; - $this->common->validate_data_check(array( + $this->helper->assert_validate_data($expected, array( 'empty' => '', 'foobar_any' => 'foobar', 'foobar_mixed' => 'FooBar', @@ -206,13 +206,24 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case 'foobar_mixed' => array('password'), 'foobar_alpha' => array('password'), 'foobar_symbol' => array('password'), - ), - $expected); + )); } public function test_validate_jabber() { - $this->common->validate_data_check(array( + $this->helper->assert_validate_data(array( + 'empty' => array(), + 'no_seperator' => array('WRONG_DATA'), + 'no_user' => array('WRONG_DATA'), + 'no_realm' => array('WRONG_DATA'), + 'dot_realm' => array('WRONG_DATA'), + '-realm' => array('WRONG_DATA'), + 'realm-' => array('WRONG_DATA'), + 'correct' => array(), + 'prohibited' => array('WRONG_DATA'), + 'prohibited_char' => array('WRONG_DATA'), + ), + array( 'empty' => '', 'no_seperator' => 'testjabber.ccc', 'no_user' => '@jabber.ccc', @@ -235,18 +246,6 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case 'correct' => array('jabber'), 'prohibited' => array('jabber'), 'prohibited_char' => array('jabber'), - ), - array( - 'empty' => array(), - 'no_seperator' => array('WRONG_DATA'), - 'no_user' => array('WRONG_DATA'), - 'no_realm' => array('WRONG_DATA'), - 'dot_realm' => array('WRONG_DATA'), - '-realm' => array('WRONG_DATA'), - 'realm-' => array('WRONG_DATA'), - 'correct' => array(), - 'prohibited' => array('WRONG_DATA'), - 'prohibited_char' => array('WRONG_DATA'), )); } } diff --git a/tests/functions/validate_email_test.php b/tests/functions/validate_email_test.php index 47aa37e11f..2e81d3277e 100644 --- a/tests/functions/validate_email_test.php +++ b/tests/functions/validate_email_test.php @@ -10,13 +10,13 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php'; require_once dirname(__FILE__) . '/../mock/user.php'; -require_once dirname(__FILE__) . '/common_validate_data.php'; +require_once dirname(__FILE__) . '/validate_data_helper.php'; class phpbb_functions_validate_email_test extends phpbb_database_test_case { protected $db; protected $user; - protected $common; + protected $helper; public function getDataSet() { @@ -29,7 +29,7 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $this->user = new phpbb_mock_user; - $this->common = new phpbb_functions_common_validate_data; + $this->helper = new phpbb_functions_validate_data_helper($this); } public function test_validate_email() @@ -41,7 +41,16 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case $user = $this->user; $user->optionset('banned_users', array('banned@example.com')); - $this->common->validate_data_check(array( + $this->helper->assert_validate_data(array( + 'empty' => array(), + 'allowed' => array(), + 'invalid' => array('EMAIL_INVALID'), + 'valid_complex' => array(), + 'taken' => array('EMAIL_TAKEN'), + 'banned' => array('EMAIL_BANNED'), + 'no_mx' => array('DOMAIN_NO_MX_RECORD'), + ), + array( 'empty' => '', 'allowed' => 'foobar@example.com', 'invalid' => 'fööbar@example.com', @@ -58,15 +67,6 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case 'taken' => array('email'), 'banned' => array('email'), 'no_mx' => array('email'), - ), - array( - 'empty' => array(), - 'allowed' => array(), - 'invalid' => array('EMAIL_INVALID'), - 'valid_complex' => array(), - 'taken' => array('EMAIL_TAKEN'), - 'banned' => array('EMAIL_BANNED'), - 'no_mx' => array('DOMAIN_NO_MX_RECORD'), )); } } diff --git a/tests/functions/validate_lang_iso_test.php b/tests/functions/validate_lang_iso_test.php index b8a1827432..baf75108b7 100644 --- a/tests/functions/validate_lang_iso_test.php +++ b/tests/functions/validate_lang_iso_test.php @@ -8,12 +8,12 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php'; -require_once dirname(__FILE__) . '/common_validate_data.php'; +require_once dirname(__FILE__) . '/validate_data_helper.php'; class phpbb_functions_validate_lang_iso_test extends phpbb_database_test_case { protected $db; - protected $common; + protected $helper; public function getDataSet() { @@ -25,7 +25,7 @@ class phpbb_functions_validate_lang_iso_test extends phpbb_database_test_case parent::setUp(); $this->db = $this->new_dbal(); - $this->common = new phpbb_functions_common_validate_data; + $this->helper = new phpbb_functions_validate_data_helper($this); } public function test_validate_lang_iso() @@ -34,7 +34,13 @@ class phpbb_functions_validate_lang_iso_test extends phpbb_database_test_case $db = $this->db; - $this->common->validate_data_check(array( + $this->helper->assert_validate_data(array( + 'empty' => array('WRONG_DATA'), + 'en' => array(), + 'cs' => array(), + 'de' => array('WRONG_DATA'), + ), + array( 'empty' => '', 'en' => 'en', 'cs' => 'cs', @@ -45,12 +51,6 @@ class phpbb_functions_validate_lang_iso_test extends phpbb_database_test_case 'en' => array('language_iso_name'), 'cs' => array('language_iso_name'), 'de' => array('language_iso_name'), - ), - array( - 'empty' => array('WRONG_DATA'), - 'en' => array(), - 'cs' => array(), - 'de' => array('WRONG_DATA'), )); } } diff --git a/tests/functions/validate_username_test.php b/tests/functions/validate_username_test.php index 656248cec3..92c5ba6ee1 100644 --- a/tests/functions/validate_username_test.php +++ b/tests/functions/validate_username_test.php @@ -10,13 +10,13 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; require_once dirname(__FILE__) . '/../mock/cache.php'; -require_once dirname(__FILE__) . '/common_validate_data.php'; +require_once dirname(__FILE__) . '/validate_data_helper.php'; class phpbb_functions_validate_data_test extends phpbb_database_test_case { protected $db; protected $cache; - protected $common; + protected $helper; public function getDataSet() { @@ -29,7 +29,7 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $this->cache = new phpbb_mock_cache; - $this->common = new phpbb_functions_common_validate_data; + $this->helper = new phpbb_functions_validate_data_helper($this); } public function validate_username_data() @@ -129,7 +129,7 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case $config['allow_name_chars'] = $allow_name_chars; - $this->common->validate_data_check(array( + $this->helper->assert_validate_data($expected, array( 'foobar_allow' => 'foobar', 'foobar_ascii' => 'foobar', 'foobar_any' => 'f*~*^=oo_bar1', @@ -154,7 +154,6 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case 'barfoo_disallow' => array('username'), 'admin_taken' => array('username'), 'group_taken' => array('username'), - ), - $expected); + )); } } From c2bc82ebfd54cebba03bd04dccaf5a8e317844ae Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 3 Jun 2013 16:15:08 +0200 Subject: [PATCH 037/113] [ticket/11579] Move simple tests into seperate files PHPBB3-11579 --- tests/functions/validate_data_simple_test.php | 251 ------------------ tests/functions/validate_date_test.php | 66 +++++ tests/functions/validate_jabber_test.php | 63 +++++ tests/functions/validate_match_test.php | 45 ++++ tests/functions/validate_num_test.php | 51 ++++ tests/functions/validate_password_test.php | 83 ++++++ tests/functions/validate_string_test.php | 58 ++++ 7 files changed, 366 insertions(+), 251 deletions(-) delete mode 100644 tests/functions/validate_data_simple_test.php create mode 100644 tests/functions/validate_date_test.php create mode 100644 tests/functions/validate_jabber_test.php create mode 100644 tests/functions/validate_match_test.php create mode 100644 tests/functions/validate_num_test.php create mode 100644 tests/functions/validate_password_test.php create mode 100644 tests/functions/validate_string_test.php diff --git a/tests/functions/validate_data_simple_test.php b/tests/functions/validate_data_simple_test.php deleted file mode 100644 index db4f218eed..0000000000 --- a/tests/functions/validate_data_simple_test.php +++ /dev/null @@ -1,251 +0,0 @@ -helper = new phpbb_functions_validate_data_helper($this); - } - - public function test_validate_string() - { - $this->helper->assert_validate_data(array( - 'empty_opt' => array(), - 'empty' => array(), - 'foo' => array(), - 'foo_minmax_correct' => array(), - 'foo_minmax_short' => array('TOO_SHORT'), - 'foo_minmax_long' => array('TOO_LONG'), - 'empty_short' => array('TOO_SHORT'), - 'empty_length_opt' => array(), - ), - array( - 'empty_opt' => '', - 'empty' => '', - 'foo' => 'foobar', - 'foo_minmax_correct' => 'foobar', - 'foo_minmax_short' => 'foobar', - 'foo_minmax_long' => 'foobar', - 'empty_short' => '', - 'empty_length_opt' => '', - ), - array( - 'empty_opt' => array('string', true), - 'empty' => array('string'), - 'foo' => array('string'), - 'foo_minmax_correct' => array('string', false, 2, 6), - 'foo_minmax_short' => array('string', false, 7, 9), - 'foo_minmax_long' => array('string', false, 2, 5), - 'empty_short' => array('string', false, 1, 6), - 'empty_length_opt' => array('string', true, 1, 6), - )); - } - - public function test_validate_num() - { - $this->helper->assert_validate_data(array( - 'empty' => array(), - 'zero' => array(), - 'five_minmax_correct' => array(), - 'five_minmax_short' => array('TOO_SMALL'), - 'five_minmax_long' => array('TOO_LARGE'), - 'string' => array(), - ), - array( - 'empty' => '', - 'zero' => 0, - 'five_minmax_correct' => 5, - 'five_minmax_short' => 5, - 'five_minmax_long' => 5, - 'string' => 'foobar', - ), - array( - 'empty' => array('num'), - 'zero' => array('num'), - 'five_minmax_correct' => array('num', false, 2, 6), - 'five_minmax_short' => array('num', false, 7, 10), - 'five_minmax_long' => array('num', false, 2, 3), - 'string' => array('num'), - )); - } - - public function test_validate_date() - { - $this->helper->assert_validate_data(array( - 'empty' => array('INVALID'), - 'empty_opt' => array(), - 'double_single' => array(), - 'single_single' => array(), - 'double_double' => array(), - // Currently fails - //'zero_year' => array(), - 'month_high' => array('INVALID'), - 'month_low' => array('INVALID'), - 'day_high' => array('INVALID'), - 'day_low' => array('INVALID'), - ), - array( - 'empty' => '', - 'empty_opt' => '', - 'double_single' => '17-06-1990', - 'single_single' => '05-05-2009', - 'double_double' => '17-12-1990', - // Currently fails - //'zero_year' => '01-01-0000', - 'month_high' => '17-17-1990', - 'month_low' => '01-00-1990', - 'day_high' => '64-01-1990', - 'day_low' => '00-12-1990', - ), - array( - 'empty' => array('date'), - 'empty_opt' => array('date', true), - 'double_single' => array('date'), - 'single_single' => array('date'), - 'double_double' => array('date'), - // Currently fails - //'zero_year' => array('date'), - 'month_high' => array('date'), - 'month_low' => array('date'), - 'day_high' => array('date'), - 'day_low' => array('date'), - )); - } - - public function test_validate_match() - { - $this->helper->assert_validate_data(array( - 'empty_opt' => array(), - 'empty_empty_match' => array(), - 'foobar' => array(), - 'foobar_fail' => array('WRONG_DATA'), - ), - array( - 'empty_opt' => '', - 'empty_empty_match' => '', - 'foobar' => 'foobar', - 'foobar_fail' => 'foobar123', - ), - array( - 'empty_opt' => array('match', true, '/[a-z]$/'), - 'empty_empty_match' => array('match'), - 'foobar' => array('match', false, '/[a-z]$/'), - 'foobar_fail' => array('match', false, '/[a-z]$/'), - )); - } - - public function validate_password_data() - { - return array( - array('PASS_TYPE_ANY', array( - 'empty' => array(), - 'foobar_any' => array(), - 'foobar_mixed' => array(), - 'foobar_alpha' => array(), - 'foobar_symbol' => array(), - )), - array('PASS_TYPE_CASE', array( - 'empty' => array(), - 'foobar_any' => array('INVALID_CHARS'), - 'foobar_mixed' => array(), - 'foobar_alpha' => array(), - 'foobar_symbol' => array(), - )), - array('PASS_TYPE_ALPHA', array( - 'empty' => array(), - 'foobar_any' => array('INVALID_CHARS'), - 'foobar_mixed' => array('INVALID_CHARS'), - 'foobar_alpha' => array(), - 'foobar_symbol' => array(), - )), - array('PASS_TYPE_SYMBOL', array( - 'empty' => array(), - 'foobar_any' => array('INVALID_CHARS'), - 'foobar_mixed' => array('INVALID_CHARS'), - 'foobar_alpha' => array('INVALID_CHARS'), - 'foobar_symbol' => array(), - )), - ); - } - - /** - * @dataProvider validate_password_data - */ - public function test_validate_password($pass_complexity, $expected) - { - global $config; - - // Set complexity to mixed case letters, numbers and symbols - $config['pass_complex'] = $pass_complexity; - - $this->helper->assert_validate_data($expected, array( - 'empty' => '', - 'foobar_any' => 'foobar', - 'foobar_mixed' => 'FooBar', - 'foobar_alpha' => 'F00bar', - 'foobar_symbol' => 'fooBar123*', - ), - array( - 'empty' => array('password'), - 'foobar_any' => array('password'), - 'foobar_mixed' => array('password'), - 'foobar_alpha' => array('password'), - 'foobar_symbol' => array('password'), - )); - } - - public function test_validate_jabber() - { - $this->helper->assert_validate_data(array( - 'empty' => array(), - 'no_seperator' => array('WRONG_DATA'), - 'no_user' => array('WRONG_DATA'), - 'no_realm' => array('WRONG_DATA'), - 'dot_realm' => array('WRONG_DATA'), - '-realm' => array('WRONG_DATA'), - 'realm-' => array('WRONG_DATA'), - 'correct' => array(), - 'prohibited' => array('WRONG_DATA'), - 'prohibited_char' => array('WRONG_DATA'), - ), - array( - 'empty' => '', - 'no_seperator' => 'testjabber.ccc', - 'no_user' => '@jabber.ccc', - 'no_realm' => 'user@', - 'dot_realm' => 'user@.....', - '-realm' => 'user@-jabber.ccc', - 'realm-' => 'user@jabber.ccc-', - 'correct' => 'user@jabber.09A-z.org', - 'prohibited' => 'u@ser@jabber.ccc.org', - 'prohibited_char' => 'uer@jabber.ccc.org', - ), - array( - 'empty' => array('jabber'), - 'no_seperator' => array('jabber'), - 'no_user' => array('jabber'), - 'no_realm' => array('jabber'), - 'dot_realm' => array('jabber'), - '-realm' => array('jabber'), - 'realm-' => array('jabber'), - 'correct' => array('jabber'), - 'prohibited' => array('jabber'), - 'prohibited_char' => array('jabber'), - )); - } -} diff --git a/tests/functions/validate_date_test.php b/tests/functions/validate_date_test.php new file mode 100644 index 0000000000..e7a279879c --- /dev/null +++ b/tests/functions/validate_date_test.php @@ -0,0 +1,66 @@ +helper = new phpbb_functions_validate_data_helper($this); + } + + public function test_validate_date() + { + $this->helper->assert_validate_data(array( + 'empty' => array('INVALID'), + 'empty_opt' => array(), + 'double_single' => array(), + 'single_single' => array(), + 'double_double' => array(), + // Currently fails + //'zero_year' => array(), + 'month_high' => array('INVALID'), + 'month_low' => array('INVALID'), + 'day_high' => array('INVALID'), + 'day_low' => array('INVALID'), + ), + array( + 'empty' => '', + 'empty_opt' => '', + 'double_single' => '17-06-1990', + 'single_single' => '05-05-2009', + 'double_double' => '17-12-1990', + // Currently fails + //'zero_year' => '01-01-0000', + 'month_high' => '17-17-1990', + 'month_low' => '01-00-1990', + 'day_high' => '64-01-1990', + 'day_low' => '00-12-1990', + ), + array( + 'empty' => array('date'), + 'empty_opt' => array('date', true), + 'double_single' => array('date'), + 'single_single' => array('date'), + 'double_double' => array('date'), + // Currently fails + //'zero_year' => array('date'), + 'month_high' => array('date'), + 'month_low' => array('date'), + 'day_high' => array('date'), + 'day_low' => array('date'), + )); + } +} diff --git a/tests/functions/validate_jabber_test.php b/tests/functions/validate_jabber_test.php new file mode 100644 index 0000000000..551b243f81 --- /dev/null +++ b/tests/functions/validate_jabber_test.php @@ -0,0 +1,63 @@ +helper = new phpbb_functions_validate_data_helper($this); + } + + public function test_validate_jabber() + { + $this->helper->assert_validate_data(array( + 'empty' => array(), + 'no_seperator' => array('WRONG_DATA'), + 'no_user' => array('WRONG_DATA'), + 'no_realm' => array('WRONG_DATA'), + 'dot_realm' => array('WRONG_DATA'), + '-realm' => array('WRONG_DATA'), + 'realm-' => array('WRONG_DATA'), + 'correct' => array(), + 'prohibited' => array('WRONG_DATA'), + 'prohibited_char' => array('WRONG_DATA'), + ), + array( + 'empty' => '', + 'no_seperator' => 'testjabber.ccc', + 'no_user' => '@jabber.ccc', + 'no_realm' => 'user@', + 'dot_realm' => 'user@.....', + '-realm' => 'user@-jabber.ccc', + 'realm-' => 'user@jabber.ccc-', + 'correct' => 'user@jabber.09A-z.org', + 'prohibited' => 'u@ser@jabber.ccc.org', + 'prohibited_char' => 'uer@jabber.ccc.org', + ), + array( + 'empty' => array('jabber'), + 'no_seperator' => array('jabber'), + 'no_user' => array('jabber'), + 'no_realm' => array('jabber'), + 'dot_realm' => array('jabber'), + '-realm' => array('jabber'), + 'realm-' => array('jabber'), + 'correct' => array('jabber'), + 'prohibited' => array('jabber'), + 'prohibited_char' => array('jabber'), + )); + } +} diff --git a/tests/functions/validate_match_test.php b/tests/functions/validate_match_test.php new file mode 100644 index 0000000000..5d44f1e00b --- /dev/null +++ b/tests/functions/validate_match_test.php @@ -0,0 +1,45 @@ +helper = new phpbb_functions_validate_data_helper($this); + } + + public function test_validate_match() + { + $this->helper->assert_validate_data(array( + 'empty_opt' => array(), + 'empty_empty_match' => array(), + 'foobar' => array(), + 'foobar_fail' => array('WRONG_DATA'), + ), + array( + 'empty_opt' => '', + 'empty_empty_match' => '', + 'foobar' => 'foobar', + 'foobar_fail' => 'foobar123', + ), + array( + 'empty_opt' => array('match', true, '/[a-z]$/'), + 'empty_empty_match' => array('match'), + 'foobar' => array('match', false, '/[a-z]$/'), + 'foobar_fail' => array('match', false, '/[a-z]$/'), + )); + } +} diff --git a/tests/functions/validate_num_test.php b/tests/functions/validate_num_test.php new file mode 100644 index 0000000000..4e210ba29a --- /dev/null +++ b/tests/functions/validate_num_test.php @@ -0,0 +1,51 @@ +helper = new phpbb_functions_validate_data_helper($this); + } + + public function test_validate_num() + { + $this->helper->assert_validate_data(array( + 'empty' => array(), + 'zero' => array(), + 'five_minmax_correct' => array(), + 'five_minmax_short' => array('TOO_SMALL'), + 'five_minmax_long' => array('TOO_LARGE'), + 'string' => array(), + ), + array( + 'empty' => '', + 'zero' => 0, + 'five_minmax_correct' => 5, + 'five_minmax_short' => 5, + 'five_minmax_long' => 5, + 'string' => 'foobar', + ), + array( + 'empty' => array('num'), + 'zero' => array('num'), + 'five_minmax_correct' => array('num', false, 2, 6), + 'five_minmax_short' => array('num', false, 7, 10), + 'five_minmax_long' => array('num', false, 2, 3), + 'string' => array('num'), + )); + } +} diff --git a/tests/functions/validate_password_test.php b/tests/functions/validate_password_test.php new file mode 100644 index 0000000000..e8dc7e0dea --- /dev/null +++ b/tests/functions/validate_password_test.php @@ -0,0 +1,83 @@ +helper = new phpbb_functions_validate_data_helper($this); + } + + public function validate_password_data() + { + return array( + array('PASS_TYPE_ANY', array( + 'empty' => array(), + 'foobar_any' => array(), + 'foobar_mixed' => array(), + 'foobar_alpha' => array(), + 'foobar_symbol' => array(), + )), + array('PASS_TYPE_CASE', array( + 'empty' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_mixed' => array(), + 'foobar_alpha' => array(), + 'foobar_symbol' => array(), + )), + array('PASS_TYPE_ALPHA', array( + 'empty' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_mixed' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_symbol' => array(), + )), + array('PASS_TYPE_SYMBOL', array( + 'empty' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_mixed' => array('INVALID_CHARS'), + 'foobar_alpha' => array('INVALID_CHARS'), + 'foobar_symbol' => array(), + )), + ); + } + + /** + * @dataProvider validate_password_data + */ + public function test_validate_password($pass_complexity, $expected) + { + global $config; + + // Set complexity to mixed case letters, numbers and symbols + $config['pass_complex'] = $pass_complexity; + + $this->helper->assert_validate_data($expected, array( + 'empty' => '', + 'foobar_any' => 'foobar', + 'foobar_mixed' => 'FooBar', + 'foobar_alpha' => 'F00bar', + 'foobar_symbol' => 'fooBar123*', + ), + array( + 'empty' => array('password'), + 'foobar_any' => array('password'), + 'foobar_mixed' => array('password'), + 'foobar_alpha' => array('password'), + 'foobar_symbol' => array('password'), + )); + } +} diff --git a/tests/functions/validate_string_test.php b/tests/functions/validate_string_test.php new file mode 100644 index 0000000000..2b4f7321a6 --- /dev/null +++ b/tests/functions/validate_string_test.php @@ -0,0 +1,58 @@ +helper = new phpbb_functions_validate_data_helper($this); + } + + public function test_validate_string() + { + $this->helper->assert_validate_data(array( + 'empty_opt' => array(), + 'empty' => array(), + 'foo' => array(), + 'foo_minmax_correct' => array(), + 'foo_minmax_short' => array('TOO_SHORT'), + 'foo_minmax_long' => array('TOO_LONG'), + 'empty_short' => array('TOO_SHORT'), + 'empty_length_opt' => array(), + ), + array( + 'empty_opt' => '', + 'empty' => '', + 'foo' => 'foobar', + 'foo_minmax_correct' => 'foobar', + 'foo_minmax_short' => 'foobar', + 'foo_minmax_long' => 'foobar', + 'empty_short' => '', + 'empty_length_opt' => '', + ), + array( + 'empty_opt' => array('string', true), + 'empty' => array('string'), + 'foo' => array('string'), + 'foo_minmax_correct' => array('string', false, 2, 6), + 'foo_minmax_short' => array('string', false, 7, 9), + 'foo_minmax_long' => array('string', false, 2, 5), + 'empty_short' => array('string', false, 1, 6), + 'empty_length_opt' => array('string', true, 1, 6), + )); + } +} From 11678678b810c26376728166cf334550cbc30124 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 3 Jun 2013 21:30:13 +0200 Subject: [PATCH 038/113] [ticket/11579] Rework calls to validate_data_helper PHPBB3-11579 --- tests/functions/validate_data_helper.php | 18 ++--- tests/functions/validate_date_test.php | 90 +++++++++++++--------- tests/functions/validate_email_test.php | 62 ++++++++------- tests/functions/validate_jabber_test.php | 86 ++++++++++++--------- tests/functions/validate_lang_iso_test.php | 38 +++++---- tests/functions/validate_match_test.php | 38 +++++---- tests/functions/validate_num_test.php | 54 +++++++------ tests/functions/validate_password_test.php | 39 ++++++---- tests/functions/validate_string_test.php | 70 ++++++++++------- tests/functions/validate_username_test.php | 81 +++++++++++++------ 10 files changed, 344 insertions(+), 232 deletions(-) diff --git a/tests/functions/validate_data_helper.php b/tests/functions/validate_data_helper.php index b8e8bfded3..94ddf60429 100644 --- a/tests/functions/validate_data_helper.php +++ b/tests/functions/validate_data_helper.php @@ -20,19 +20,17 @@ class phpbb_functions_validate_data_helper extends PHPUnit_Framework_TestCase * Test provided input data with supplied checks and compare to expected * results * - * @param array $expected Array containing the expected results. Either - * an array containing the error message or the an empty - * array if input is correct - * @param array $input Input data with specific array keys that need to - * be matched by the ones in the other 2 params - * @param array $validate_check Array containing validate_data check - * settings, i.e. array('foobar' => array('string')) + * @param array $data Array containing one or more subarrays with the + * test data. The first element of a subarray is the + * expected result, the second one is the input, and the + * third is the data that should be passed to the function + * validate_data(). */ - public function assert_validate_data($expected, $input, $validate_check) + public function assert_valid_data($data) { - foreach ($input as $key => $data) + foreach ($data as $key => $test) { - $this->test_case->assertEquals($expected[$key], validate_data(array($data), array($validate_check[$key]))); + $this->test_case->assertEquals($test[0], validate_data(array($test[1]), array($test[2]))); } } } diff --git a/tests/functions/validate_date_test.php b/tests/functions/validate_date_test.php index e7a279879c..1dcd1361a2 100644 --- a/tests/functions/validate_date_test.php +++ b/tests/functions/validate_date_test.php @@ -23,44 +23,60 @@ class phpbb_functions_validate_date_test extends phpbb_test_case public function test_validate_date() { - $this->helper->assert_validate_data(array( - 'empty' => array('INVALID'), - 'empty_opt' => array(), - 'double_single' => array(), - 'single_single' => array(), - 'double_double' => array(), + $this->helper->assert_valid_data(array( + 'empty' => array( + array('INVALID'), + '', + array('date'), + ), + 'empty_opt' => array( + array(), + '', + array('date', true), + ), + 'double_single' => array( + array(), + '17-06-1990', + array('date'), + ), + 'single_single' => array( + array(), + '05-05-2009', + array('date'), + ), + 'double_double' => array( + array(), + '17-12-1990', + array('date'), + ), + 'month_high' => array( + array('INVALID'), + '17-17-1990', + array('date'), + ), + 'month_low' => array( + array('INVALID'), + '01-00-1990', + array('date'), + ), + 'day_high' => array( + array('INVALID'), + '64-01-1990', + array('date'), + ), + 'day_low' => array( + array('INVALID'), + '00-12-1990', + array('date'), + ), // Currently fails - //'zero_year' => array(), - 'month_high' => array('INVALID'), - 'month_low' => array('INVALID'), - 'day_high' => array('INVALID'), - 'day_low' => array('INVALID'), - ), - array( - 'empty' => '', - 'empty_opt' => '', - 'double_single' => '17-06-1990', - 'single_single' => '05-05-2009', - 'double_double' => '17-12-1990', - // Currently fails - //'zero_year' => '01-01-0000', - 'month_high' => '17-17-1990', - 'month_low' => '01-00-1990', - 'day_high' => '64-01-1990', - 'day_low' => '00-12-1990', - ), - array( - 'empty' => array('date'), - 'empty_opt' => array('date', true), - 'double_single' => array('date'), - 'single_single' => array('date'), - 'double_double' => array('date'), - // Currently fails - //'zero_year' => array('date'), - 'month_high' => array('date'), - 'month_low' => array('date'), - 'day_high' => array('date'), - 'day_low' => array('date'), + /* + 'zero_year' => array( + array(), + '01-01-0000', + array('date'), + ), + */ )); } } diff --git a/tests/functions/validate_email_test.php b/tests/functions/validate_email_test.php index 2e81d3277e..93b5ba0896 100644 --- a/tests/functions/validate_email_test.php +++ b/tests/functions/validate_email_test.php @@ -41,32 +41,42 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case $user = $this->user; $user->optionset('banned_users', array('banned@example.com')); - $this->helper->assert_validate_data(array( - 'empty' => array(), - 'allowed' => array(), - 'invalid' => array('EMAIL_INVALID'), - 'valid_complex' => array(), - 'taken' => array('EMAIL_TAKEN'), - 'banned' => array('EMAIL_BANNED'), - 'no_mx' => array('DOMAIN_NO_MX_RECORD'), - ), - array( - 'empty' => '', - 'allowed' => 'foobar@example.com', - 'invalid' => 'fööbar@example.com', - 'valid_complex' => "'%$~test@example.com", - 'taken' => 'admin@example.com', - 'banned' => 'banned@example.com', - 'no_mx' => 'test@wwrrrhhghgghgh.ttv', - ), - array( - 'empty' => array('email'), - 'allowed' => array('email', 'foobar@example.com'), - 'invalid' => array('email'), - 'valid_complex' => array('email'), - 'taken' => array('email'), - 'banned' => array('email'), - 'no_mx' => array('email'), + $this->helper->assert_valid_data(array( + 'empty' => array( + array(), + '', + array('email'), + ), + 'allowed' => array( + array(), + 'foobar@example.com', + array('email', 'foobar@example.com'), + ), + 'invalid' => array( + array('EMAIL_INVALID'), + 'fööbar@example.com', + array('email'), + ), + 'valid_complex' => array( + array(), + "'%$~test@example.com", + array('email'), + ), + 'taken' => array( + array('EMAIL_TAKEN'), + 'admin@example.com', + array('email'), + ), + 'banned' => array( + array('EMAIL_BANNED'), + 'banned@example.com', + array('email'), + ), + 'no_mx' => array( + array('DOMAIN_NO_MX_RECORD'), + 'test@wwrrrhhghgghgh.ttv', + array('email'), + ), )); } } diff --git a/tests/functions/validate_jabber_test.php b/tests/functions/validate_jabber_test.php index 551b243f81..5a53c963bd 100644 --- a/tests/functions/validate_jabber_test.php +++ b/tests/functions/validate_jabber_test.php @@ -23,41 +23,57 @@ class phpbb_functions_validate_jabber_test extends phpbb_test_case public function test_validate_jabber() { - $this->helper->assert_validate_data(array( - 'empty' => array(), - 'no_seperator' => array('WRONG_DATA'), - 'no_user' => array('WRONG_DATA'), - 'no_realm' => array('WRONG_DATA'), - 'dot_realm' => array('WRONG_DATA'), - '-realm' => array('WRONG_DATA'), - 'realm-' => array('WRONG_DATA'), - 'correct' => array(), - 'prohibited' => array('WRONG_DATA'), - 'prohibited_char' => array('WRONG_DATA'), - ), - array( - 'empty' => '', - 'no_seperator' => 'testjabber.ccc', - 'no_user' => '@jabber.ccc', - 'no_realm' => 'user@', - 'dot_realm' => 'user@.....', - '-realm' => 'user@-jabber.ccc', - 'realm-' => 'user@jabber.ccc-', - 'correct' => 'user@jabber.09A-z.org', - 'prohibited' => 'u@ser@jabber.ccc.org', - 'prohibited_char' => 'uer@jabber.ccc.org', - ), - array( - 'empty' => array('jabber'), - 'no_seperator' => array('jabber'), - 'no_user' => array('jabber'), - 'no_realm' => array('jabber'), - 'dot_realm' => array('jabber'), - '-realm' => array('jabber'), - 'realm-' => array('jabber'), - 'correct' => array('jabber'), - 'prohibited' => array('jabber'), - 'prohibited_char' => array('jabber'), + $this->helper->assert_valid_data(array( + 'empty' => array( + array(), + '', + array('jabber'), + ), + 'no_seperator' => array( + array('WRONG_DATA'), + 'testjabber.ccc', + array('jabber'), + ), + 'no_user' => array( + array('WRONG_DATA'), + '@jabber.ccc', + array('jabber'), + ), + 'no_realm' => array( + array('WRONG_DATA'), + 'user@', + array('jabber'), + ), + 'dot_realm' => array( + array('WRONG_DATA'), + 'user@.....', + array('jabber'), + ), + '-realm' => array( + array('WRONG_DATA'), + 'user@-jabber.ccc', + array('jabber'), + ), + 'realm-' => array( + array('WRONG_DATA'), + 'user@jabber.ccc-', + array('jabber'), + ), + 'correct' => array( + array(), + 'user@jabber.09A-z.org', + array('jabber'), + ), + 'prohibited' => array( + array('WRONG_DATA'), + 'u@ser@jabber.ccc.org', + array('jabber'), + ), + 'prohibited_char' => array( + array('WRONG_DATA'), + 'uer@jabber.ccc.org', + array('jabber'), + ), )); } } diff --git a/tests/functions/validate_lang_iso_test.php b/tests/functions/validate_lang_iso_test.php index baf75108b7..c8a5b71021 100644 --- a/tests/functions/validate_lang_iso_test.php +++ b/tests/functions/validate_lang_iso_test.php @@ -34,23 +34,27 @@ class phpbb_functions_validate_lang_iso_test extends phpbb_database_test_case $db = $this->db; - $this->helper->assert_validate_data(array( - 'empty' => array('WRONG_DATA'), - 'en' => array(), - 'cs' => array(), - 'de' => array('WRONG_DATA'), - ), - array( - 'empty' => '', - 'en' => 'en', - 'cs' => 'cs', - 'de' => 'de', - ), - array( - 'empty' => array('language_iso_name'), - 'en' => array('language_iso_name'), - 'cs' => array('language_iso_name'), - 'de' => array('language_iso_name'), + $this->helper->assert_valid_data(array( + 'empty' => array( + array('WRONG_DATA'), + '', + array('language_iso_name'), + ), + 'en' => array( + array(), + 'en', + array('language_iso_name'), + ), + 'cs' => array( + array(), + 'cs', + array('language_iso_name'), + ), + 'de' => array( + array('WRONG_DATA'), + 'de', + array('language_iso_name'), + ), )); } } diff --git a/tests/functions/validate_match_test.php b/tests/functions/validate_match_test.php index 5d44f1e00b..73a363e003 100644 --- a/tests/functions/validate_match_test.php +++ b/tests/functions/validate_match_test.php @@ -23,23 +23,27 @@ class phpbb_functions_validate_match_test extends phpbb_test_case public function test_validate_match() { - $this->helper->assert_validate_data(array( - 'empty_opt' => array(), - 'empty_empty_match' => array(), - 'foobar' => array(), - 'foobar_fail' => array('WRONG_DATA'), - ), - array( - 'empty_opt' => '', - 'empty_empty_match' => '', - 'foobar' => 'foobar', - 'foobar_fail' => 'foobar123', - ), - array( - 'empty_opt' => array('match', true, '/[a-z]$/'), - 'empty_empty_match' => array('match'), - 'foobar' => array('match', false, '/[a-z]$/'), - 'foobar_fail' => array('match', false, '/[a-z]$/'), + $this->helper->assert_valid_data(array( + 'empty_opt' => array( + array(), + '', + array('match', true, '/[a-z]$/'), + ), + 'empty_empty_match' => array( + array(), + '', + array('match'), + ), + 'foobar' => array( + array(), + 'foobar', + array('match', false, '/[a-z]$/'), + ), + 'foobar_fail' => array( + array('WRONG_DATA'), + 'foobar123', + array('match', false, '/[a-z]$/'), + ), )); } } diff --git a/tests/functions/validate_num_test.php b/tests/functions/validate_num_test.php index 4e210ba29a..4deac02ebc 100644 --- a/tests/functions/validate_num_test.php +++ b/tests/functions/validate_num_test.php @@ -23,29 +23,37 @@ class phpbb_functions_validate_num_test extends phpbb_test_case public function test_validate_num() { - $this->helper->assert_validate_data(array( - 'empty' => array(), - 'zero' => array(), - 'five_minmax_correct' => array(), - 'five_minmax_short' => array('TOO_SMALL'), - 'five_minmax_long' => array('TOO_LARGE'), - 'string' => array(), - ), - array( - 'empty' => '', - 'zero' => 0, - 'five_minmax_correct' => 5, - 'five_minmax_short' => 5, - 'five_minmax_long' => 5, - 'string' => 'foobar', - ), - array( - 'empty' => array('num'), - 'zero' => array('num'), - 'five_minmax_correct' => array('num', false, 2, 6), - 'five_minmax_short' => array('num', false, 7, 10), - 'five_minmax_long' => array('num', false, 2, 3), - 'string' => array('num'), + $this->helper->assert_valid_data(array( + 'empty' => array( + array(), + '', + array('num'), + ), + 'zero' => array( + array(), + '0', + array('num'), + ), + 'five_minmax_correct' => array( + array(), + '5', + array('num', false, 2, 6), + ), + 'five_minmax_short' => array( + array('TOO_SMALL'), + '5', + array('num', false, 7, 10), + ), + 'five_minmax_long' => array( + array('TOO_LARGE'), + '5', + array('num', false, 2, 3), + ), + 'string' => array( + array(), + 'foobar', + array('num'), + ), )); } } diff --git a/tests/functions/validate_password_test.php b/tests/functions/validate_password_test.php index e8dc7e0dea..4639f6cc89 100644 --- a/tests/functions/validate_password_test.php +++ b/tests/functions/validate_password_test.php @@ -65,19 +65,32 @@ class phpbb_functions_validate_password_test extends phpbb_test_case // Set complexity to mixed case letters, numbers and symbols $config['pass_complex'] = $pass_complexity; - $this->helper->assert_validate_data($expected, array( - 'empty' => '', - 'foobar_any' => 'foobar', - 'foobar_mixed' => 'FooBar', - 'foobar_alpha' => 'F00bar', - 'foobar_symbol' => 'fooBar123*', - ), - array( - 'empty' => array('password'), - 'foobar_any' => array('password'), - 'foobar_mixed' => array('password'), - 'foobar_alpha' => array('password'), - 'foobar_symbol' => array('password'), + $this->helper->assert_valid_data(array( + 'empty' => array( + $expected['empty'], + '', + array('password'), + ), + 'foobar_any' => array( + $expected['foobar_any'], + 'foobar', + array('password'), + ), + 'foobar_mixed' => array( + $expected['foobar_mixed'], + 'FooBar', + array('password'), + ), + 'foobar_alpha' => array( + $expected['foobar_alpha'], + 'F00bar', + array('password'), + ), + 'foobar_symbol' => array( + $expected['foobar_symbol'], + 'fooBar123*', + array('password'), + ), )); } } diff --git a/tests/functions/validate_string_test.php b/tests/functions/validate_string_test.php index 2b4f7321a6..ab44c28541 100644 --- a/tests/functions/validate_string_test.php +++ b/tests/functions/validate_string_test.php @@ -24,35 +24,47 @@ class phpbb_functions_validate_string_test extends phpbb_test_case public function test_validate_string() { - $this->helper->assert_validate_data(array( - 'empty_opt' => array(), - 'empty' => array(), - 'foo' => array(), - 'foo_minmax_correct' => array(), - 'foo_minmax_short' => array('TOO_SHORT'), - 'foo_minmax_long' => array('TOO_LONG'), - 'empty_short' => array('TOO_SHORT'), - 'empty_length_opt' => array(), - ), - array( - 'empty_opt' => '', - 'empty' => '', - 'foo' => 'foobar', - 'foo_minmax_correct' => 'foobar', - 'foo_minmax_short' => 'foobar', - 'foo_minmax_long' => 'foobar', - 'empty_short' => '', - 'empty_length_opt' => '', - ), - array( - 'empty_opt' => array('string', true), - 'empty' => array('string'), - 'foo' => array('string'), - 'foo_minmax_correct' => array('string', false, 2, 6), - 'foo_minmax_short' => array('string', false, 7, 9), - 'foo_minmax_long' => array('string', false, 2, 5), - 'empty_short' => array('string', false, 1, 6), - 'empty_length_opt' => array('string', true, 1, 6), + $this->helper->assert_valid_data(array( + 'empty_opt' => array( + array(), + '', + array('string', true), + ), + 'empty' => array( + array(), + '', + array('string'), + ), + 'foo' => array( + array(), + 'foobar', + array('string'), + ), + 'foo_minmax_correct' => array( + array(), + 'foobar', + array('string', false, 2, 6), + ), + 'foo_minmax_short' => array( + array('TOO_SHORT'), + 'foobar', + array('string', false, 7, 9), + ), + 'foo_minmax_long' => array( + array('TOO_LONG'), + 'foobar', + array('string', false, 2, 5), + ), + 'empty_short' => array( + array('TOO_SHORT'), + '', + array('string', false, 1, 6), + ), + 'empty_length_opt' => array( + array(), + '', + array('string', true, 1, 6), + ), )); } } diff --git a/tests/functions/validate_username_test.php b/tests/functions/validate_username_test.php index 92c5ba6ee1..9adfb63812 100644 --- a/tests/functions/validate_username_test.php +++ b/tests/functions/validate_username_test.php @@ -129,31 +129,62 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case $config['allow_name_chars'] = $allow_name_chars; - $this->helper->assert_validate_data($expected, array( - 'foobar_allow' => 'foobar', - 'foobar_ascii' => 'foobar', - 'foobar_any' => 'f*~*^=oo_bar1', - 'foobar_alpha' => 'fo0Bar', - 'foobar_alpha_spacers' => 'Fo0-[B]_a+ R', - 'foobar_letter_num' => 'fo0Bar0', - 'foobar_letter_num_sp' => 'Fö0-[B]_a+ R', - 'foobar_quot' => '"foobar"', - 'barfoo_disallow' => 'barfoo', - 'admin_taken' => 'admin', - 'group_taken' => 'foobar_group', - ), - array( - 'foobar_allow' => array('username', 'foobar'), - 'foobar_ascii' => array('username'), - 'foobar_any' => array('username'), - 'foobar_alpha' => array('username'), - 'foobar_alpha_spacers' => array('username'), - 'foobar_letter_num' => array('username'), - 'foobar_letter_num_sp' => array('username'), - 'foobar_quot' => array('username'), - 'barfoo_disallow' => array('username'), - 'admin_taken' => array('username'), - 'group_taken' => array('username'), + $this->helper->assert_valid_data(array( + 'foobar_allow' => array( + $expected['foobar_allow'], + 'foobar', + array('username', 'foobar'), + ), + 'foobar_ascii' => array( + $expected['foobar_ascii'], + 'foobar', + array('username'), + ), + 'foobar_any' => array( + $expected['foobar_any'], + 'f*~*^=oo_bar1', + array('username'), + ), + 'foobar_alpha' => array( + $expected['foobar_alpha'], + 'fo0Bar', + array('username'), + ), + 'foobar_alpha_spacers' => array( + $expected['foobar_alpha_spacers'], + 'Fo0-[B]_a+ R', + array('username'), + ), + 'foobar_letter_num' => array( + $expected['foobar_letter_num'], + 'fo0Bar0', + array('username'), + ), + 'foobar_letter_num_sp' => array( + $expected['foobar_letter_num_sp'], + 'Fö0-[B]_a+ R', + array('username'), + ), + 'foobar_quot' => array( + $expected['foobar_quot'], + '"foobar"', + array('username'), + ), + 'barfoo_disallow' => array( + $expected['barfoo_disallow'], + 'barfoo', + array('username'), + ), + 'admin_taken' => array( + $expected['admin_taken'], + 'admin', + array('username'), + ), + 'group_taken' => array( + $expected['group_taken'], + 'foobar_group', + array('username'), + ), )); } } From b288bd441436c8dd3417f67013729732ca87939f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 3 Jun 2013 21:33:02 +0200 Subject: [PATCH 039/113] [ticket/11579] Add missing commas to validate_username_test PHPBB3-11579 --- tests/functions/validate_username_test.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/functions/validate_username_test.php b/tests/functions/validate_username_test.php index 9adfb63812..0819974e54 100644 --- a/tests/functions/validate_username_test.php +++ b/tests/functions/validate_username_test.php @@ -46,7 +46,7 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case 'foobar_quot' => array('INVALID_CHARS'), 'barfoo_disallow' => array('USERNAME_DISALLOWED'), 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('USERNAME_TAKEN') + 'group_taken' => array('USERNAME_TAKEN'), )), array('USERNAME_ALPHA_ONLY', array( 'foobar_allow' => array(), @@ -59,7 +59,7 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case 'foobar_quot' => array('INVALID_CHARS'), 'barfoo_disallow' => array('USERNAME_DISALLOWED'), 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('INVALID_CHARS') + 'group_taken' => array('INVALID_CHARS'), )), array('USERNAME_ALPHA_SPACERS', array( 'foobar_allow' => array(), @@ -72,7 +72,7 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case 'foobar_quot' => array('INVALID_CHARS'), 'barfoo_disallow' => array('USERNAME_DISALLOWED'), 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('USERNAME_TAKEN') + 'group_taken' => array('USERNAME_TAKEN'), )), array('USERNAME_LETTER_NUM', array( 'foobar_allow' => array(), @@ -85,7 +85,7 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case 'foobar_quot' => array('INVALID_CHARS'), 'barfoo_disallow' => array('USERNAME_DISALLOWED'), 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('INVALID_CHARS') + 'group_taken' => array('INVALID_CHARS'), )), array('USERNAME_LETTER_NUM_SPACERS', array( 'foobar_allow' => array(), @@ -98,7 +98,7 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case 'foobar_quot' => array('INVALID_CHARS'), 'barfoo_disallow' => array('USERNAME_DISALLOWED'), 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('USERNAME_TAKEN') + 'group_taken' => array('USERNAME_TAKEN'), )), array('USERNAME_ASCII', array( 'foobar_allow' => array(), @@ -111,7 +111,7 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case 'foobar_quot' => array('INVALID_CHARS'), 'barfoo_disallow' => array('USERNAME_DISALLOWED'), 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('USERNAME_TAKEN') + 'group_taken' => array('USERNAME_TAKEN'), )), ); } From 6a77ee1f30961f6363818691f91162fa67618872 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 5 Jun 2013 17:05:10 +0200 Subject: [PATCH 040/113] [ticket/11579] Do not extend validate_data_helper PHPBB3-11579 --- tests/functions/validate_data_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functions/validate_data_helper.php b/tests/functions/validate_data_helper.php index 94ddf60429..b92a3aa5eb 100644 --- a/tests/functions/validate_data_helper.php +++ b/tests/functions/validate_data_helper.php @@ -7,7 +7,7 @@ * */ -class phpbb_functions_validate_data_helper extends PHPUnit_Framework_TestCase +class phpbb_functions_validate_data_helper { protected $test_case; From c6ba894acdfdf5b0800dc3903d01605ddd83e8e9 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 5 Jun 2013 17:36:20 +0200 Subject: [PATCH 041/113] [ticket/11579] Add method for validating emails for valid MX and mark as slow A method for setting up the prerequisities also has been added in order to reduce the amount of necessary code. PHPBB3-11579 --- tests/functions/validate_email_test.php | 32 ++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/tests/functions/validate_email_test.php b/tests/functions/validate_email_test.php index 93b5ba0896..9a6ce39251 100644 --- a/tests/functions/validate_email_test.php +++ b/tests/functions/validate_email_test.php @@ -32,14 +32,24 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case $this->helper = new phpbb_functions_validate_data_helper($this); } - public function test_validate_email() + /** + * Get validation prerequesites + * + * @param bool $check_mx Whether mx records should be checked + */ + protected function set_validation_prerequisites($check_mx) { global $config, $db, $user; - $config['email_check_mx'] = true; + $config['email_check_mx'] = $check_mx; $db = $this->db; $user = $this->user; $user->optionset('banned_users', array('banned@example.com')); + } + + public function test_validate_email() + { + $this->set_validation_prerequisites(false); $this->helper->assert_valid_data(array( 'empty' => array( @@ -72,9 +82,25 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case 'banned@example.com', array('email'), ), + )); + } + + /** + * @group slow + */ + public function test_validate_email_mx() + { + $this->set_validation_prerequisites(true); + + $this->helper->assert_valid_data(array( + 'valid' => array( + array(), + 'foobar@phpbb.com', + array('email'), + ), 'no_mx' => array( array('DOMAIN_NO_MX_RECORD'), - 'test@wwrrrhhghgghgh.ttv', + 'test@does-not-exist.phpbb.com', array('email'), ), )); From 55f7281f61d774c9cac4309aee7ee12a209914f1 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 6 Jun 2013 13:00:53 +0200 Subject: [PATCH 042/113] [ticket/11588] Also use version.phpbb.com in install_update.php. PHPBB3-11588 --- phpBB/install/install_update.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index ec76f2a407..c18a0fb4ec 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -1656,7 +1656,9 @@ class install_update extends module { case 'version_info': global $phpbb_root_path, $phpEx; - $info = get_remote_file('www.phpbb.com', '/updatecheck', ((defined('PHPBB_QA')) ? '30x_qa.txt' : '30x.txt'), $errstr, $errno); + + $info = get_remote_file('version.phpbb.com', '/phpbb', + ((defined('PHPBB_QA')) ? '30x_qa.txt' : '30x.txt'), $errstr, $errno); if ($info !== false) { From 057bbfa2406bf659d85d137c07704f0aaddb4478 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 May 2013 15:57:17 +0200 Subject: [PATCH 043/113] [ticket/11543] Add unit tests for obtain_guest_count() PHPBB3-11543 --- tests/functions/fixtures/obtain_online.xml | 11 ++++ tests/functions/obtain_online_test.php | 69 ++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 tests/functions/fixtures/obtain_online.xml create mode 100644 tests/functions/obtain_online_test.php diff --git a/tests/functions/fixtures/obtain_online.xml b/tests/functions/fixtures/obtain_online.xml new file mode 100644 index 0000000000..ea4d6f9238 --- /dev/null +++ b/tests/functions/fixtures/obtain_online.xml @@ -0,0 +1,11 @@ + + + + session_id + session_user_id + session_forum_id + session_time + session_ip + session_viewonline +
      +
      diff --git a/tests/functions/obtain_online_test.php b/tests/functions/obtain_online_test.php new file mode 100644 index 0000000000..1089b42616 --- /dev/null +++ b/tests/functions/obtain_online_test.php @@ -0,0 +1,69 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/obtain_online.xml'); + } + + protected function setUp() + { + global $config, $db; + + $db = $this->db = $this->new_dbal(); + $config = array( + 'load_online_time' => 5, + ); + } + + static public function obtain_guest_count_data() + { + return array( + array(0, 2), + array(1, 1), + ); + } + + /** + * @dataProvider obtain_guest_count_data + */ + public function test_obtain_guest_count($forum_id, $expected) + { + $this->db->sql_query('DELETE FROM phpbb_sessions'); + + $this->create_guest_sessions(); + $this->assertEquals($expected, obtain_guest_count($forum_id)); + } + + protected function create_guest_sessions() + { + $this->add_session(1, '0001', 0, true, 0); + $this->add_session(1, '0002', 1, true, 0); + $this->add_session(1, '0003', 0, true, 10); + $this->add_session(1, '0004', 1, true, 10); + } + + protected function add_session($user_id, $user_ip, $forum_id, $view_online, $time_delta) + { + $sql_ary = array( + 'session_id' => $user_id . '_' . $forum_id . '_session00000000000000000' . $user_ip, + 'session_user_id' => $user_id, + 'session_ip' => $user_ip, + 'session_forum_id' => $forum_id, + 'session_time' => time() - $time_delta * 60, + 'session_viewonline' => $view_online, + ); + + $this->db->sql_query('INSERT INTO phpbb_sessions ' . $this->db->sql_build_array('INSERT', $sql_ary)); + } +} From 6b3758edd091f09f46b8117df39c4d104e96739b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 May 2013 15:57:57 +0200 Subject: [PATCH 044/113] [ticket/11543] Add unit tests for obtain_users_online() PHPBB3-11543 --- tests/functions/obtain_online_test.php | 65 ++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/functions/obtain_online_test.php b/tests/functions/obtain_online_test.php index 1089b42616..efb8e97fc7 100644 --- a/tests/functions/obtain_online_test.php +++ b/tests/functions/obtain_online_test.php @@ -45,6 +45,59 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case $this->assertEquals($expected, obtain_guest_count($forum_id)); } + static public function obtain_users_online_data() + { + return array( + array(0, false, array( + 'online_users' => array(2 => 2, 3 => 3, 6 => 6, 7 => 7), + 'hidden_users' => array(6 => 6, 7 => 7), + 'total_online' => 4, + 'visible_online' => 2, + 'hidden_online' => 2, + 'guests_online' => 0, + )), + array(0, true, array( + 'online_users' => array(2 => 2, 3 => 3, 6 => 6, 7 => 7), + 'hidden_users' => array(6 => 6, 7 => 7), + 'total_online' => 6, + 'visible_online' => 2, + 'hidden_online' => 2, + 'guests_online' => 2, + )), + array(1, false, array( + 'online_users' => array(3 => 3, 7 => 7), + 'hidden_users' => array(7 => 7), + 'total_online' => 2, + 'visible_online' => 1, + 'hidden_online' => 1, + 'guests_online' => 0, + )), + array(1, true, array( + 'online_users' => array(3 => 3, 7 => 7), + 'hidden_users' => array(7 => 7), + 'total_online' => 3, + 'visible_online' => 1, + 'hidden_online' => 1, + 'guests_online' => 1, + )), + ); + } + + /** + * @dataProvider obtain_users_online_data + */ + public function test_obtain_users_online($forum_id, $display_guests, $expected) + { + $this->db->sql_query('DELETE FROM phpbb_sessions'); + + global $config; + $config['load_online_guests'] = $display_guests; + + $this->create_guest_sessions(); + $this->create_user_sessions(); + $this->assertEquals($expected, obtain_users_online($forum_id)); + } + protected function create_guest_sessions() { $this->add_session(1, '0001', 0, true, 0); @@ -53,6 +106,18 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case $this->add_session(1, '0004', 1, true, 10); } + protected function create_user_sessions() + { + $this->add_session(2, '0005', 0, true, 0); + $this->add_session(3, '0006', 1, true, 0); + $this->add_session(4, '0007', 0, true, 10); + $this->add_session(5, '0008', 1, true, 10); + $this->add_session(6, '0005', 0, false, 0); + $this->add_session(7, '0006', 1, false, 0); + $this->add_session(8, '0007', 0, false, 10); + $this->add_session(9, '0008', 1, false, 10); + } + protected function add_session($user_id, $user_ip, $forum_id, $view_online, $time_delta) { $sql_ary = array( From 3301b01f4c659af15393a58b8221d62a906551be Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 May 2013 16:02:30 +0200 Subject: [PATCH 045/113] [ticket/11543] Add unit tests for obtain_users_online() with empty forum PHPBB3-11543 --- tests/functions/obtain_online_test.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/functions/obtain_online_test.php b/tests/functions/obtain_online_test.php index efb8e97fc7..8fd7e6a977 100644 --- a/tests/functions/obtain_online_test.php +++ b/tests/functions/obtain_online_test.php @@ -80,6 +80,22 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case 'hidden_online' => 1, 'guests_online' => 1, )), + array(2, false, array( + 'online_users' => array(), + 'hidden_users' => array(), + 'total_online' => 0, + 'visible_online' => 0, + 'hidden_online' => 0, + 'guests_online' => 0, + )), + array(2, true, array( + 'online_users' => array(), + 'hidden_users' => array(), + 'total_online' => 0, + 'visible_online' => 0, + 'hidden_online' => 0, + 'guests_online' => 0, + )), ); } From 766be31f95ff5b03cba0273cdfd83fb7f0d93a0b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 May 2013 17:23:17 +0200 Subject: [PATCH 046/113] [ticket/11543] Add unit tests for obtain_users_online_string() PHPBB3-11543 --- tests/functions/fixtures/obtain_online.xml | 100 +++++++++++++++++++++ tests/functions/obtain_online_test.php | 86 +++++++++++++++++- 2 files changed, 185 insertions(+), 1 deletion(-) diff --git a/tests/functions/fixtures/obtain_online.xml b/tests/functions/fixtures/obtain_online.xml index ea4d6f9238..1c5a4454f2 100644 --- a/tests/functions/fixtures/obtain_online.xml +++ b/tests/functions/fixtures/obtain_online.xml @@ -8,4 +8,104 @@ session_ip session_viewonline + + user_id + username_clean + username + user_allow_viewonline + user_permissions + user_sig + user_occ + user_interests + + 1 + anonymous + anonymous + 1 + + + + + + + 2 + 2 + 2 + 1 + + + + + + + 3 + 3 + 3 + 1 + + + + + + + 4 + 4 + 4 + 1 + + + + + + + 5 + 5 + 5 + 1 + + + + + + + 6 + 6 + 6 + 0 + + + + + + + 7 + 7 + 7 + 0 + + + + + + + 8 + 8 + 8 + 0 + + + + + + + 9 + 9 + 9 + 0 + + + + + +
      diff --git a/tests/functions/obtain_online_test.php b/tests/functions/obtain_online_test.php index 8fd7e6a977..64f368164c 100644 --- a/tests/functions/obtain_online_test.php +++ b/tests/functions/obtain_online_test.php @@ -8,6 +8,8 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/auth.php'; class phpbb_functions_obtain_online_test extends phpbb_database_test_case { @@ -18,6 +20,8 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case protected function setUp() { + parent::setUp(); + global $config, $db; $db = $this->db = $this->new_dbal(); @@ -114,6 +118,63 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case $this->assertEquals($expected, obtain_users_online($forum_id)); } + static public function obtain_users_online_string_data() + { + return array( + array(0, false, array( + 'online_userlist' => 'REGISTERED_USERS 2, 3', + 'l_online_users' => 'ONLINE_USERS_TOTAL 4REG_USERS_TOTAL_AND 2HIDDEN_USERS_TOTAL 2', + )), + array(0, true, array( + 'online_userlist' => 'REGISTERED_USERS 2, 3', + 'l_online_users' => 'ONLINE_USERS_TOTAL 6REG_USERS_TOTAL 2HIDDEN_USERS_TOTAL_AND 2GUEST_USERS_TOTAL 2', + )), + array(1, false, array( + 'online_userlist' => 'BROWSING_FORUM 3', + 'l_online_users' => 'ONLINE_USERS_TOTAL 2REG_USER_TOTAL_AND 1HIDDEN_USER_TOTAL 1', + )), + array(1, true, array( + 'online_userlist' => 'BROWSING_FORUM_GUEST 3 1', + 'l_online_users' => 'ONLINE_USERS_TOTAL 3REG_USER_TOTAL 1HIDDEN_USER_TOTAL_AND 1GUEST_USER_TOTAL 1', + )), + array(2, false, array( + 'online_userlist' => 'BROWSING_FORUM NO_ONLINE_USERS', + 'l_online_users' => 'ONLINE_USERS_ZERO_TOTAL 0REG_USERS_ZERO_TOTAL_AND 0HIDDEN_USERS_ZERO_TOTAL 0', + )), + array(2, true, array( + 'online_userlist' => 'BROWSING_FORUM_GUESTS NO_ONLINE_USERS 0', + 'l_online_users' => 'ONLINE_USERS_ZERO_TOTAL 0REG_USERS_ZERO_TOTAL 0HIDDEN_USERS_ZERO_TOTAL_AND 0GUEST_USERS_ZERO_TOTAL 0', + )), + ); + } + + /** + * @dataProvider obtain_users_online_string_data + */ + public function test_obtain_users_online_string($forum_id, $display_guests, $expected) + { + $this->db->sql_query('DELETE FROM phpbb_sessions'); + + global $config, $user, $auth; + $config['load_online_guests'] = $display_guests; + $user->lang = $this->load_language(); + $auth = $this->getMock('auth'); + $acl_get_map = array( + array('u_viewonline', true), + ); + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), + $this->anything()) + ->will($this->returnValueMap($acl_get_map)); + + $this->create_guest_sessions(); + $this->create_user_sessions(); + + $online_users = obtain_users_online($forum_id); + $this->assertEquals($expected, obtain_users_online_string($online_users, $forum_id)); + } + protected function create_guest_sessions() { $this->add_session(1, '0001', 0, true, 0); @@ -144,7 +205,30 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case 'session_time' => time() - $time_delta * 60, 'session_viewonline' => $view_online, ); - $this->db->sql_query('INSERT INTO phpbb_sessions ' . $this->db->sql_build_array('INSERT', $sql_ary)); } + + protected function load_language() + { + $lang = array( + 'NO_ONLINE_USERS' => 'NO_ONLINE_USERS', + 'REGISTERED_USERS' => 'REGISTERED_USERS', + 'BROWSING_FORUM' => 'BROWSING_FORUM %s', + 'BROWSING_FORUM_GUEST' => 'BROWSING_FORUM_GUEST %s %d', + 'BROWSING_FORUM_GUESTS' => 'BROWSING_FORUM_GUESTS %s %d', + ); + $vars_online = array('ONLINE', 'REG', 'HIDDEN', 'GUEST'); + foreach ($vars_online as $online) + { + $lang = array_merge($lang, array( + $online . '_USERS_ZERO_TOTAL' => $online . '_USERS_ZERO_TOTAL %d', + $online . '_USER_TOTAL' => $online . '_USER_TOTAL %d', + $online . '_USERS_TOTAL' => $online . '_USERS_TOTAL %d', + $online . '_USERS_ZERO_TOTAL_AND' => $online . '_USERS_ZERO_TOTAL_AND %d', + $online . '_USER_TOTAL_AND' => $online . '_USER_TOTAL_AND %d', + $online . '_USERS_TOTAL_AND' => $online . '_USERS_TOTAL_AND %d', + )); + } + return $lang; + } } From ba665412ea4342da24b70408335e82a8c455f258 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 28 May 2013 17:56:48 +0200 Subject: [PATCH 047/113] [ticket/11543] Use correct IP addresses and inject time for correct values PHPBB3-11543 --- tests/functions/obtain_online_test.php | 47 ++++++++++++++------------ 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/tests/functions/obtain_online_test.php b/tests/functions/obtain_online_test.php index 64f368164c..941c20de92 100644 --- a/tests/functions/obtain_online_test.php +++ b/tests/functions/obtain_online_test.php @@ -45,7 +45,8 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case { $this->db->sql_query('DELETE FROM phpbb_sessions'); - $this->create_guest_sessions(); + $time = time(); + $this->create_guest_sessions($time); $this->assertEquals($expected, obtain_guest_count($forum_id)); } @@ -113,8 +114,9 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case global $config; $config['load_online_guests'] = $display_guests; - $this->create_guest_sessions(); - $this->create_user_sessions(); + $time = time(); + $this->create_guest_sessions($time); + $this->create_user_sessions($time); $this->assertEquals($expected, obtain_users_online($forum_id)); } @@ -168,41 +170,42 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case $this->anything()) ->will($this->returnValueMap($acl_get_map)); - $this->create_guest_sessions(); - $this->create_user_sessions(); + $time = time(); + $this->create_guest_sessions($time); + $this->create_user_sessions($time); $online_users = obtain_users_online($forum_id); $this->assertEquals($expected, obtain_users_online_string($online_users, $forum_id)); } - protected function create_guest_sessions() + protected function create_guest_sessions($time) { - $this->add_session(1, '0001', 0, true, 0); - $this->add_session(1, '0002', 1, true, 0); - $this->add_session(1, '0003', 0, true, 10); - $this->add_session(1, '0004', 1, true, 10); + $this->add_session(1, '0001', '192.168.0.1', 0, true, $time); + $this->add_session(1, '0002', '192.168.0.2', 1, true, $time); + $this->add_session(1, '0003', '192.168.0.3', 0, true, $time, 10); + $this->add_session(1, '0004', '192.168.0.4', 1, true, $time, 10); } - protected function create_user_sessions() + protected function create_user_sessions($time) { - $this->add_session(2, '0005', 0, true, 0); - $this->add_session(3, '0006', 1, true, 0); - $this->add_session(4, '0007', 0, true, 10); - $this->add_session(5, '0008', 1, true, 10); - $this->add_session(6, '0005', 0, false, 0); - $this->add_session(7, '0006', 1, false, 0); - $this->add_session(8, '0007', 0, false, 10); - $this->add_session(9, '0008', 1, false, 10); + $this->add_session(2, '0005', '192.168.0.5', 0, true, $time); + $this->add_session(3, '0006', '192.168.0.6', 1, true, $time); + $this->add_session(4, '0007', '192.168.0.7', 0, true, $time, 10); + $this->add_session(5, '0008', '192.168.0.8', 1, true, $time, 10); + $this->add_session(6, '0005', '192.168.0.9', 0, false, $time); + $this->add_session(7, '0006', '192.168.0.10', 1, false, $time); + $this->add_session(8, '0007', '192.168.0.11', 0, false, $time, 10); + $this->add_session(9, '0008', '192.168.0.12', 1, false, $time, 10); } - protected function add_session($user_id, $user_ip, $forum_id, $view_online, $time_delta) + protected function add_session($user_id, $session_id, $user_ip, $forum_id, $view_online, $time, $time_delta = 0) { $sql_ary = array( - 'session_id' => $user_id . '_' . $forum_id . '_session00000000000000000' . $user_ip, + 'session_id' => $user_id . '_' . $forum_id . '_session00000000000000000' . $session_id, 'session_user_id' => $user_id, 'session_ip' => $user_ip, 'session_forum_id' => $forum_id, - 'session_time' => time() - $time_delta * 60, + 'session_time' => $time - $time_delta * 60, 'session_viewonline' => $view_online, ); $this->db->sql_query('INSERT INTO phpbb_sessions ' . $this->db->sql_build_array('INSERT', $sql_ary)); From 228c1075b765e8d51a997935bf12f973ae02264e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 Jun 2013 01:31:20 +0200 Subject: [PATCH 048/113] [ticket/11590] Close database connections when tearDown() is called PHPBB3-11590 --- .../phpbb_database_test_case.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 429bb92bf1..beddece470 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -11,6 +11,8 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test { static private $already_connected; + private $db_connections; + protected $test_case_helpers; protected $fixture_xml_data; @@ -28,6 +30,22 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test 'phpbb_database_test_case' => array('already_connected'), ); + + $this->db_connections = array(); + } + + protected function tearDown() + { + parent::tearDown(); + + // Close all database connections from this test + if (!empty($this->db_connections)) + { + foreach ($this->db_connections as $db) + { + $db->sql_close(); + } + } } protected function setUp() @@ -123,6 +141,8 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $db = new $dbal(); $db->sql_connect($config['dbhost'], $config['dbuser'], $config['dbpasswd'], $config['dbname'], $config['dbport']); + $this->db_connections[] = $db; + return $db; } From d39ed5afc13285c1d6d14ea0d04be87dd11f7d38 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 Jun 2013 14:48:50 +0200 Subject: [PATCH 049/113] [ticket/11543] Add more users so #hidden <> #normal PHPBB3-11543 --- tests/functions/fixtures/obtain_online.xml | 10 ++++++++++ tests/functions/obtain_online_test.php | 21 +++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/tests/functions/fixtures/obtain_online.xml b/tests/functions/fixtures/obtain_online.xml index 1c5a4454f2..05bbe6a05e 100644 --- a/tests/functions/fixtures/obtain_online.xml +++ b/tests/functions/fixtures/obtain_online.xml @@ -107,5 +107,15 @@ + + 10 + 10 + 10 + 0 + + + + + diff --git a/tests/functions/obtain_online_test.php b/tests/functions/obtain_online_test.php index 941c20de92..b3beb55a96 100644 --- a/tests/functions/obtain_online_test.php +++ b/tests/functions/obtain_online_test.php @@ -54,19 +54,19 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case { return array( array(0, false, array( - 'online_users' => array(2 => 2, 3 => 3, 6 => 6, 7 => 7), - 'hidden_users' => array(6 => 6, 7 => 7), - 'total_online' => 4, + 'online_users' => array(2 => 2, 3 => 3, 6 => 6, 7 => 7, 10 => 10), + 'hidden_users' => array(6 => 6, 7 => 7, 10 => 10), + 'total_online' => 5, 'visible_online' => 2, - 'hidden_online' => 2, + 'hidden_online' => 3, 'guests_online' => 0, )), array(0, true, array( - 'online_users' => array(2 => 2, 3 => 3, 6 => 6, 7 => 7), - 'hidden_users' => array(6 => 6, 7 => 7), - 'total_online' => 6, + 'online_users' => array(2 => 2, 3 => 3, 6 => 6, 7 => 7, 10 => 10), + 'hidden_users' => array(6 => 6, 7 => 7, 10 => 10), + 'total_online' => 7, 'visible_online' => 2, - 'hidden_online' => 2, + 'hidden_online' => 3, 'guests_online' => 2, )), array(1, false, array( @@ -125,11 +125,11 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case return array( array(0, false, array( 'online_userlist' => 'REGISTERED_USERS 2, 3', - 'l_online_users' => 'ONLINE_USERS_TOTAL 4REG_USERS_TOTAL_AND 2HIDDEN_USERS_TOTAL 2', + 'l_online_users' => 'ONLINE_USERS_TOTAL 5REG_USERS_TOTAL_AND 2HIDDEN_USERS_TOTAL 3', )), array(0, true, array( 'online_userlist' => 'REGISTERED_USERS 2, 3', - 'l_online_users' => 'ONLINE_USERS_TOTAL 6REG_USERS_TOTAL 2HIDDEN_USERS_TOTAL_AND 2GUEST_USERS_TOTAL 2', + 'l_online_users' => 'ONLINE_USERS_TOTAL 7REG_USERS_TOTAL 2HIDDEN_USERS_TOTAL_AND 3GUEST_USERS_TOTAL 2', )), array(1, false, array( 'online_userlist' => 'BROWSING_FORUM 3', @@ -196,6 +196,7 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case $this->add_session(7, '0006', '192.168.0.10', 1, false, $time); $this->add_session(8, '0007', '192.168.0.11', 0, false, $time, 10); $this->add_session(9, '0008', '192.168.0.12', 1, false, $time, 10); + $this->add_session(10, '009', '192.168.0.13', 0, false, $time); } protected function add_session($user_id, $session_id, $user_ip, $forum_id, $view_online, $time, $time_delta = 0) From 5e8054f04598c449799a594fcb96cfeb8abf925a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Jun 2013 13:24:55 +0200 Subject: [PATCH 050/113] [ticket/11601] Split post_setup_synchronisation logic from xml parsing PHPBB3-11601 --- ...phpbb_database_test_connection_manager.php | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index bcd52b1794..30f1fa6589 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -480,12 +480,33 @@ class phpbb_database_test_connection_manager * @return null */ public function post_setup_synchronisation($xml_data_set) + { + $table_names = $xml_data_set->getTableNames(); + + $tables = array(); + foreach ($table_names as $table) + { + $tables[$table] = $xml_data_set->getTableMetaData($table)->getColumns(); + } + + $this->database_synchronisation($tables); + } + + /** + * Performs synchronisations on the database after a fixture has been loaded + * + * @param array $table_column_map Array of tables/columns to synchronise + * array(table1 => array(column1, column2)) + * + * @return null + */ + public function database_synchronisation($table_column_map) { $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()); + // Get escaped versions of the table names to synchronise + $table_names = array_map(array($this->pdo, 'PDO::quote'), array_keys($table_column_map)); switch ($this->config['dbms']) { @@ -542,7 +563,7 @@ class phpbb_database_test_connection_manager 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(); + $column_names = $table_column_map[$row['table_name']]; // Skip sequences that weren't specified in the fixture if (!in_array($row['column_name'], $column_names)) From 33bce3fac6c29787e121e5d000251353637dd422 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Jun 2013 13:26:17 +0200 Subject: [PATCH 051/113] [ticket/11601] Add protected method for database sync and call it PHPBB3-11601 --- tests/test_framework/phpbb_database_test_case.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index beddece470..28d3a716f0 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -62,6 +62,21 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test } } + /** + * Performs synchronisations for a given table/column set on the database + * + * @param array $table_column_map Information about the tables/columns to synchronise + * + * @return null + */ + protected function database_synchronisation($table_column_map) + { + $config = $this->get_database_config(); + $manager = $this->create_connection_manager($config); + $manager->connect(); + $manager->database_synchronisation($table_column_map); + } + public function createXMLDataSet($path) { $db_config = $this->get_database_config(); From fbebc2874fb7f9462b7cf2481a14166cfb906297 Mon Sep 17 00:00:00 2001 From: riadhchtara Date: Sat, 21 Apr 2012 17:43:13 +0200 Subject: [PATCH 052/113] [ticket/10820] Image downloader recognize new version of ie When a user download image attachement using ie8, the file is displayed. However, when he uses ie version greater than 8, the image is download. A changes are made to phpbb/download/file.php to solve the problem. We check now if the ie version is greater or equal to 8 and not only equal to 8 PHPBB3-10820 --- phpBB/download/file.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 3ceb1ee0cc..b942c92a1c 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -285,7 +285,7 @@ else if (($display_cat == ATTACHMENT_CATEGORY_NONE/* || $display_cat == ATTACHME $db->sql_query($sql); } -if ($display_cat == ATTACHMENT_CATEGORY_IMAGE && $mode === 'view' && (strpos($attachment['mimetype'], 'image') === 0) && ((strpos(strtolower($user->browser), 'msie') !== false) && (strpos(strtolower($user->browser), 'msie 8.0') === false))) +if ($display_cat == ATTACHMENT_CATEGORY_IMAGE && $mode === 'view' && (strpos($attachment['mimetype'], 'image') === 0) && !is_greater_ie7($user->browser)) { wrap_img_in_html(append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'id=' . $attachment['attach_id']), $attachment['real_filename']); file_gc(); @@ -343,8 +343,8 @@ function send_avatar_to_browser($file, $browser) $image_data = @getimagesize($file_path); header('Content-Type: ' . image_type_to_mime_type($image_data[2])); - - if (strpos(strtolower($browser), 'msie') !== false && strpos(strtolower($browser), 'msie 8.0') === false) + + if (strpos(strtolower($browser), 'msie') !== false && !is_greater_ie7($user->browser)) { header('Content-Disposition: attachment; ' . header_filename($file)); @@ -477,10 +477,9 @@ function send_file_to_browser($attachment, $upload_dir, $category) */ // Send out the Headers. Do not set Content-Disposition to inline please, it is a security measure for users using the Internet Explorer. - $is_ie8 = (strpos(strtolower($user->browser), 'msie 8.0') !== false); header('Content-Type: ' . $attachment['mimetype']); - - if ($is_ie8) + + if (is_greater_ie7($user->browser)) { header('X-Content-Type-Options: nosniff'); } @@ -492,7 +491,7 @@ function send_file_to_browser($attachment, $upload_dir, $category) } else { - if (empty($user->browser) || (!$is_ie8 && (strpos(strtolower($user->browser), 'msie') !== false))) + if (empty($user->browser) || (!is_greater_ie7($user->browser) && (strpos(strtolower($user->browser), 'msie') !== false))) { header('Content-Disposition: attachment; ' . header_filename(htmlspecialchars_decode($attachment['real_filename']))); if (empty($user->browser) || (strpos(strtolower($user->browser), 'msie 6.0') !== false)) @@ -503,7 +502,7 @@ function send_file_to_browser($attachment, $upload_dir, $category) else { header('Content-Disposition: ' . ((strpos($attachment['mimetype'], 'image') === 0) ? 'inline' : 'attachment') . '; ' . header_filename(htmlspecialchars_decode($attachment['real_filename']))); - if ($is_ie8 && (strpos($attachment['mimetype'], 'image') !== 0)) + if (is_greater_ie7($user->browser) && (strpos($attachment['mimetype'], 'image') !== 0)) { header('X-Download-Options: noopen'); } @@ -680,7 +679,8 @@ function set_modified_headers($stamp, $browser) { // let's see if we have to send the file at all $last_load = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime(trim($_SERVER['HTTP_IF_MODIFIED_SINCE'])) : false; - if ((strpos(strtolower($browser), 'msie 6.0') === false) && (strpos(strtolower($browser), 'msie 8.0') === false)) + + if ((strpos(strtolower($browser), 'msie 6.0') === false) && (!is_greater_ie7($user->browser))) { if ($last_load !== false && $last_load >= $stamp) { @@ -709,4 +709,9 @@ function file_gc() exit; } +function is_greater_ie7($browser) +{ + return preg_match('/msie (\d{2,3}|[89]+).[0-9.]*;/', strtolower($browser)); +} + ?> \ No newline at end of file From 80d164b12151c3b3d5eb42d1874a0a1d3b288d12 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 7 Feb 2013 23:59:46 +0530 Subject: [PATCH 053/113] [ticket/10820] proper usage of global and local variable browser PHPBB3-10820 --- phpBB/download/file.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index b942c92a1c..6764ee7eac 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -344,7 +344,7 @@ function send_avatar_to_browser($file, $browser) $image_data = @getimagesize($file_path); header('Content-Type: ' . image_type_to_mime_type($image_data[2])); - if (strpos(strtolower($browser), 'msie') !== false && !is_greater_ie7($user->browser)) + if (strpos(strtolower($browser), 'msie') !== false && !is_greater_ie7($browser)) { header('Content-Disposition: attachment; ' . header_filename($file)); @@ -680,7 +680,7 @@ function set_modified_headers($stamp, $browser) // let's see if we have to send the file at all $last_load = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime(trim($_SERVER['HTTP_IF_MODIFIED_SINCE'])) : false; - if ((strpos(strtolower($browser), 'msie 6.0') === false) && (!is_greater_ie7($user->browser))) + if ((strpos(strtolower($browser), 'msie 6.0') === false) && (!is_greater_ie7($browser))) { if ($last_load !== false && $last_load >= $stamp) { From 9236f12577087e5b800b9c23e988a671702f1a9e Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 8 Feb 2013 00:05:06 +0530 Subject: [PATCH 054/113] [ticket/10820] fix IE check function Add phpbb_ prefix to function name and return boolean value. PHPBB3-10820 --- phpBB/download/file.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 6764ee7eac..af41951c46 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -285,7 +285,7 @@ else if (($display_cat == ATTACHMENT_CATEGORY_NONE/* || $display_cat == ATTACHME $db->sql_query($sql); } -if ($display_cat == ATTACHMENT_CATEGORY_IMAGE && $mode === 'view' && (strpos($attachment['mimetype'], 'image') === 0) && !is_greater_ie7($user->browser)) +if ($display_cat == ATTACHMENT_CATEGORY_IMAGE && $mode === 'view' && (strpos($attachment['mimetype'], 'image') === 0) && !phpbb_is_greater_ie7($user->browser)) { wrap_img_in_html(append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'id=' . $attachment['attach_id']), $attachment['real_filename']); file_gc(); @@ -344,7 +344,7 @@ function send_avatar_to_browser($file, $browser) $image_data = @getimagesize($file_path); header('Content-Type: ' . image_type_to_mime_type($image_data[2])); - if (strpos(strtolower($browser), 'msie') !== false && !is_greater_ie7($browser)) + if (strpos(strtolower($browser), 'msie') !== false && !phpbb_is_greater_ie7($browser)) { header('Content-Disposition: attachment; ' . header_filename($file)); @@ -479,7 +479,7 @@ function send_file_to_browser($attachment, $upload_dir, $category) // Send out the Headers. Do not set Content-Disposition to inline please, it is a security measure for users using the Internet Explorer. header('Content-Type: ' . $attachment['mimetype']); - if (is_greater_ie7($user->browser)) + if (phpbb_is_greater_ie7($user->browser)) { header('X-Content-Type-Options: nosniff'); } @@ -491,7 +491,7 @@ function send_file_to_browser($attachment, $upload_dir, $category) } else { - if (empty($user->browser) || (!is_greater_ie7($user->browser) && (strpos(strtolower($user->browser), 'msie') !== false))) + if (empty($user->browser) || (!phpbb_is_greater_ie7($user->browser) && (strpos(strtolower($user->browser), 'msie') !== false))) { header('Content-Disposition: attachment; ' . header_filename(htmlspecialchars_decode($attachment['real_filename']))); if (empty($user->browser) || (strpos(strtolower($user->browser), 'msie 6.0') !== false)) @@ -502,7 +502,7 @@ function send_file_to_browser($attachment, $upload_dir, $category) else { header('Content-Disposition: ' . ((strpos($attachment['mimetype'], 'image') === 0) ? 'inline' : 'attachment') . '; ' . header_filename(htmlspecialchars_decode($attachment['real_filename']))); - if (is_greater_ie7($user->browser) && (strpos($attachment['mimetype'], 'image') !== 0)) + if (phpbb_is_greater_ie7($user->browser) && (strpos($attachment['mimetype'], 'image') !== 0)) { header('X-Download-Options: noopen'); } @@ -680,7 +680,7 @@ function set_modified_headers($stamp, $browser) // let's see if we have to send the file at all $last_load = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime(trim($_SERVER['HTTP_IF_MODIFIED_SINCE'])) : false; - if ((strpos(strtolower($browser), 'msie 6.0') === false) && (!is_greater_ie7($browser))) + if ((strpos(strtolower($browser), 'msie 6.0') === false) && (!phpbb_is_greater_ie7($browser))) { if ($last_load !== false && $last_load >= $stamp) { @@ -709,9 +709,9 @@ function file_gc() exit; } -function is_greater_ie7($browser) +function phpbb_is_greater_ie7($browser) { - return preg_match('/msie (\d{2,3}|[89]+).[0-9.]*;/', strtolower($browser)); + return (bool) preg_match('/msie (\d{2,3}|[89]+).[0-9.]*;/', strtolower($browser)); } ?> \ No newline at end of file From 875914767414da7ef7076f444542c09bd0b83c72 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 8 Feb 2013 13:58:41 +0530 Subject: [PATCH 055/113] [ticket/10820] add function docblock PHPBB3-10820 --- phpBB/download/file.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index af41951c46..abab473bf2 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -709,6 +709,10 @@ function file_gc() exit; } +/** +* Check if the browser is internet explorer version 7+ +* @returns true if ie7+ +*/ function phpbb_is_greater_ie7($browser) { return (bool) preg_match('/msie (\d{2,3}|[89]+).[0-9.]*;/', strtolower($browser)); From 07c62dd64f65551012bd942be29179cfae99d7ab Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 4 Mar 2013 22:44:19 +0530 Subject: [PATCH 056/113] [ticket/10820] remove unnecessary condition checks PHPBB3-10820 --- phpBB/download/file.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index abab473bf2..8bb77efe4d 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -344,7 +344,7 @@ function send_avatar_to_browser($file, $browser) $image_data = @getimagesize($file_path); header('Content-Type: ' . image_type_to_mime_type($image_data[2])); - if (strpos(strtolower($browser), 'msie') !== false && !phpbb_is_greater_ie7($browser)) + if (!phpbb_is_greater_ie7($browser)) { header('Content-Disposition: attachment; ' . header_filename($file)); @@ -491,7 +491,7 @@ function send_file_to_browser($attachment, $upload_dir, $category) } else { - if (empty($user->browser) || (!phpbb_is_greater_ie7($user->browser) && (strpos(strtolower($user->browser), 'msie') !== false))) + if (empty($user->browser) || !phpbb_is_greater_ie7($user->browser)) { header('Content-Disposition: attachment; ' . header_filename(htmlspecialchars_decode($attachment['real_filename']))); if (empty($user->browser) || (strpos(strtolower($user->browser), 'msie 6.0') !== false)) From 364828de24c14a73d98621b545f7732c18b18a4d Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 13 Apr 2013 22:48:09 +0530 Subject: [PATCH 057/113] [ticket/10820] Use singular return PHPBB3-10820 --- phpBB/download/file.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 8bb77efe4d..20d3e60580 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -711,7 +711,7 @@ function file_gc() /** * Check if the browser is internet explorer version 7+ -* @returns true if ie7+ +* @return true if ie7+ */ function phpbb_is_greater_ie7($browser) { From 687b04bcfc7a4dac8c53e9dbf5e7c31347d9d474 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 13 Apr 2013 22:50:37 +0530 Subject: [PATCH 058/113] [ticket/10820] simplify regex and escape dot PHPBB3-10820 --- phpBB/download/file.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 20d3e60580..5b274160e8 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -715,7 +715,7 @@ function file_gc() */ function phpbb_is_greater_ie7($browser) { - return (bool) preg_match('/msie (\d{2,3}|[89]+).[0-9.]*;/', strtolower($browser)); + return (bool) preg_match('/msie [^67]+\\.*;/', strtolower($browser)); } ?> \ No newline at end of file From ea7ece5d252fa8ede7d611abc812f8abc93c011d Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 27 Apr 2013 20:57:51 +0530 Subject: [PATCH 059/113] [ticket/10820] add param and return to function Add param and return in function docblock. Rename function parameter to $user_agent. PHPBB3-10820 --- phpBB/download/file.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 5b274160e8..081f18b15c 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -711,11 +711,14 @@ function file_gc() /** * Check if the browser is internet explorer version 7+ -* @return true if ie7+ +* +* @param string $user_agent User agent HTTP header +* +* @return bool true if ie7+ */ -function phpbb_is_greater_ie7($browser) +function phpbb_is_greater_ie7($user_agent) { - return (bool) preg_match('/msie [^67]+\\.*;/', strtolower($browser)); + return (bool) preg_match('/msie [^67]+\\.*;/', strtolower($user_agent)); } ?> \ No newline at end of file From 5ebebbd7190fb5e541df9956b5d58983765d931b Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 27 Apr 2013 21:33:30 +0530 Subject: [PATCH 060/113] [ticket/10820] fix docblock PHPBB3-10820 --- phpBB/download/file.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 081f18b15c..cba4ef3b7b 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -714,7 +714,7 @@ function file_gc() * * @param string $user_agent User agent HTTP header * -* @return bool true if ie7+ +* @return bool true if internet explorer version is greater than 7 */ function phpbb_is_greater_ie7($user_agent) { From 8f733cc658e20da74e910f3e36edcfdf86a7eba3 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 27 Apr 2013 23:24:22 +0530 Subject: [PATCH 061/113] [ticket/10820] remove unnecessary parentheses PHPBB3-10820 --- phpBB/download/file.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index cba4ef3b7b..f781480bb7 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -680,7 +680,7 @@ function set_modified_headers($stamp, $browser) // let's see if we have to send the file at all $last_load = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime(trim($_SERVER['HTTP_IF_MODIFIED_SINCE'])) : false; - if ((strpos(strtolower($browser), 'msie 6.0') === false) && (!phpbb_is_greater_ie7($browser))) + if (strpos(strtolower($browser), 'msie 6.0') === false && !phpbb_is_greater_ie7($browser)) { if ($last_load !== false && $last_load >= $stamp) { From 6b5780b753a857dec087d363601e54f1515213fa Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 12 May 2013 16:03:48 +0530 Subject: [PATCH 062/113] [ticket/10820] fix regex Extract IE version from user agent string and then compare it with 7 PHPBB3-10820 --- phpBB/download/file.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index f781480bb7..abc67ecdac 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -718,7 +718,15 @@ function file_gc() */ function phpbb_is_greater_ie7($user_agent) { - return (bool) preg_match('/msie [^67]+\\.*;/', strtolower($user_agent)); + if (preg_match('/msie (\d+)/', strtolower($user_agent), $matches)) + { + $ie_version = (int) $matches[1]; + return ($ie_version > 7); + } + else + { + return false; + } } ?> \ No newline at end of file From 11cd9f901e53c2e1fe2aa1f3ce5d1f0c445d7ba7 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 5 Jun 2013 00:14:46 +0530 Subject: [PATCH 063/113] [ticket/10820] Inject IE version in function PHPBB3-10820 --- phpBB/download/file.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index abc67ecdac..009fa3572a 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -285,7 +285,7 @@ else if (($display_cat == ATTACHMENT_CATEGORY_NONE/* || $display_cat == ATTACHME $db->sql_query($sql); } -if ($display_cat == ATTACHMENT_CATEGORY_IMAGE && $mode === 'view' && (strpos($attachment['mimetype'], 'image') === 0) && !phpbb_is_greater_ie7($user->browser)) +if ($display_cat == ATTACHMENT_CATEGORY_IMAGE && $mode === 'view' && (strpos($attachment['mimetype'], 'image') === 0) && !phpbb_is_greater_ie_version($user->browser, 7)) { wrap_img_in_html(append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'id=' . $attachment['attach_id']), $attachment['real_filename']); file_gc(); @@ -344,7 +344,7 @@ function send_avatar_to_browser($file, $browser) $image_data = @getimagesize($file_path); header('Content-Type: ' . image_type_to_mime_type($image_data[2])); - if (!phpbb_is_greater_ie7($browser)) + if (!phpbb_is_greater_ie_version($browser, 7)) { header('Content-Disposition: attachment; ' . header_filename($file)); @@ -479,7 +479,7 @@ function send_file_to_browser($attachment, $upload_dir, $category) // Send out the Headers. Do not set Content-Disposition to inline please, it is a security measure for users using the Internet Explorer. header('Content-Type: ' . $attachment['mimetype']); - if (phpbb_is_greater_ie7($user->browser)) + if (phpbb_is_greater_ie_version($user->browser, 7)) { header('X-Content-Type-Options: nosniff'); } @@ -491,7 +491,7 @@ function send_file_to_browser($attachment, $upload_dir, $category) } else { - if (empty($user->browser) || !phpbb_is_greater_ie7($user->browser)) + if (empty($user->browser) || !phpbb_is_greater_ie_version($user->browser, 7)) { header('Content-Disposition: attachment; ' . header_filename(htmlspecialchars_decode($attachment['real_filename']))); if (empty($user->browser) || (strpos(strtolower($user->browser), 'msie 6.0') !== false)) @@ -502,7 +502,7 @@ function send_file_to_browser($attachment, $upload_dir, $category) else { header('Content-Disposition: ' . ((strpos($attachment['mimetype'], 'image') === 0) ? 'inline' : 'attachment') . '; ' . header_filename(htmlspecialchars_decode($attachment['real_filename']))); - if (phpbb_is_greater_ie7($user->browser) && (strpos($attachment['mimetype'], 'image') !== 0)) + if (phpbb_is_greater_ie_version($user->browser, 7) && (strpos($attachment['mimetype'], 'image') !== 0)) { header('X-Download-Options: noopen'); } @@ -680,7 +680,7 @@ function set_modified_headers($stamp, $browser) // let's see if we have to send the file at all $last_load = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime(trim($_SERVER['HTTP_IF_MODIFIED_SINCE'])) : false; - if (strpos(strtolower($browser), 'msie 6.0') === false && !phpbb_is_greater_ie7($browser)) + if (strpos(strtolower($browser), 'msie 6.0') === false && !phpbb_is_greater_ie_version($browser, 7)) { if ($last_load !== false && $last_load >= $stamp) { @@ -713,15 +713,16 @@ function file_gc() * Check if the browser is internet explorer version 7+ * * @param string $user_agent User agent HTTP header +* @param int $version IE version to check against * * @return bool true if internet explorer version is greater than 7 */ -function phpbb_is_greater_ie7($user_agent) +function phpbb_is_greater_ie_version($user_agent, $version) { if (preg_match('/msie (\d+)/', strtolower($user_agent), $matches)) { $ie_version = (int) $matches[1]; - return ($ie_version > 7); + return ($ie_version > $version); } else { From e0b9cdf708cf75ac189b935dad3e816a1363de3a Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 8 Jun 2013 23:13:45 +0530 Subject: [PATCH 064/113] [ticket/10820] Fix function docblock PHPBB3-10820 --- phpBB/download/file.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 009fa3572a..e06fd117cf 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -715,7 +715,7 @@ function file_gc() * @param string $user_agent User agent HTTP header * @param int $version IE version to check against * -* @return bool true if internet explorer version is greater than 7 +* @return bool true if internet explorer version is greater than $version */ function phpbb_is_greater_ie_version($user_agent, $version) { From e633ace07267579d9860a165e288fbd1ed4ba442 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Jun 2013 14:53:03 +0200 Subject: [PATCH 065/113] [ticket/11603] Fix github api url and use curl with valid user agent PHPBB3-11603 --- git-tools/merge.php | 7 ++++++- git-tools/setup_github_network.php | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/git-tools/merge.php b/git-tools/merge.php index 41a96c0890..2acd2280b9 100755 --- a/git-tools/merge.php +++ b/git-tools/merge.php @@ -124,7 +124,12 @@ function get_repository_url($username, $repository, $ssh = false) function api_request($query) { - $contents = file_get_contents("http://github.com/api/v2/json/$query"); + $c = curl_init(); + curl_setopt($c, CURLOPT_URL, "https://api.github.com/$query"); + curl_setopt($c, CURLOPT_RETURNTRANSFER, true); + curl_setopt($c, CURLOPT_USERAGENT, 'phpBB/1.0'); + $contents = curl_exec($c); + curl_close($c); if ($contents === false) { diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index 5f2e1609a7..87ce2616e3 100755 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -145,7 +145,13 @@ function get_repository_url($username, $repository, $ssh = false) function api_request($query) { - $contents = file_get_contents("http://github.com/api/v2/json/$query"); + $c = curl_init(); + curl_setopt($c, CURLOPT_URL, "https://api.github.com/$query"); + curl_setopt($c, CURLOPT_RETURNTRANSFER, true); + curl_setopt($c, CURLOPT_USERAGENT, 'phpBB/1.0'); + $contents = curl_exec($c); + curl_close($c); + if ($contents === false) { return false; From bcc98ae3e7dce9c1c967622d2fccebbb0f07e9fe Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 12 Jun 2013 17:35:39 +0200 Subject: [PATCH 066/113] [ticket/11603] Rename network to forks and fix handling PHPBB3-11603 --- git-tools/setup_github_network.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index 87ce2616e3..95f8c86ba3 100755 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -22,7 +22,7 @@ function show_usage() echo " collaborators Repositories of people who have push access to the specified repository\n"; echo " contributors Repositories of people who have contributed to the specified repository\n"; echo " organisation Repositories of members of the organisation at github\n"; - echo " network All repositories of the whole github network\n"; + echo " forks All repositories of the whole github network\n"; echo "\n"; echo "Options:\n"; @@ -55,10 +55,10 @@ exit(work($scope, $username, $repository, $developer)); function work($scope, $username, $repository, $developer) { // Get some basic data - $network = get_network($username, $repository); + $forks = get_forks($username, $repository); $collaborators = get_collaborators($username, $repository); - if ($network === false || $collaborators === false) + if ($forks === false || $collaborators === false) { echo "Error: failed to retrieve network or collaborators\n"; return 1; @@ -67,19 +67,19 @@ function work($scope, $username, $repository, $developer) switch ($scope) { case 'collaborators': - $remotes = array_intersect_key($network, $collaborators); + $remotes = array_intersect_key($forks, $collaborators); break; case 'organisation': - $remotes = array_intersect_key($network, get_organisation_members($username)); + $remotes = array_intersect_key($forks, get_organisation_members($username)); break; case 'contributors': - $remotes = array_intersect_key($network, get_contributors($username, $repository)); + $remotes = array_intersect_key($forks, get_contributors($username, $repository)); break; - case 'network': - $remotes = $network; + case 'forks': + $remotes = $forks; break; default: @@ -210,20 +210,20 @@ function get_collaborators($username, $repository) return $usernames; } -function get_network($username, $repository) +function get_forks($username, $repository) { - $request = api_request("repos/show/$username/$repository/network"); + $request = api_request("repos/$username/$repository/forks"); if ($request === false) { return false; } $usernames = array(); - foreach ($request->network as $network) + foreach ($request as $fork) { - $usernames[$network->owner] = array( - 'username' => $network->owner, - 'repository' => $network->name, + $usernames[$fork->owner->login] = array( + 'username' => $fork->owner->login, + 'repository' => $fork->name, ); } From e4ccc5e6eac2bfebb8770a1a8f73f965ef0146fc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 13 Jun 2013 13:05:33 +0200 Subject: [PATCH 067/113] [ticket/11603] Fix github API calls - Some URLs changed - Response is a plain array now - Added error messages when API limit is reached PHPBB3-11603 --- git-tools/merge.php | 11 +++++- git-tools/setup_github_network.php | 60 ++++++++++++++++++++++++------ 2 files changed, 57 insertions(+), 14 deletions(-) diff --git a/git-tools/merge.php b/git-tools/merge.php index 2acd2280b9..5eb48a53f8 100755 --- a/git-tools/merge.php +++ b/git-tools/merge.php @@ -128,6 +128,7 @@ function api_request($query) curl_setopt($c, CURLOPT_URL, "https://api.github.com/$query"); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); curl_setopt($c, CURLOPT_USERAGENT, 'phpBB/1.0'); + curl_setopt($c, CURLOPT_HEADER, true); $contents = curl_exec($c); curl_close($c); @@ -135,13 +136,19 @@ function api_request($query) { throw new RuntimeException("Error: failed to retrieve pull request data\n", 4); } + $contents = json_decode($contents); - return json_decode($contents); + if (isset($contents->message) && strpos($contents->message, 'API Rate Limit') === 0) + { + exit('Reached github API Rate Limit. Please try again later' . "\n"); + } + + return $contents; } function get_pull($username, $repository, $pull_id) { - $request = api_request("pulls/$username/$repository/$pull_id"); + $request = api_request("repos/$username/$repository/pulls/$pull_id"); $pull = $request->pull; diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index 95f8c86ba3..de3ea55d13 100755 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -60,7 +60,7 @@ function work($scope, $username, $repository, $developer) if ($forks === false || $collaborators === false) { - echo "Error: failed to retrieve network or collaborators\n"; + echo "Error: failed to retrieve forks or collaborators\n"; return 1; } @@ -143,34 +143,70 @@ function get_repository_url($username, $repository, $ssh = false) return $url_base . $username . '/' . $repository . '.git'; } -function api_request($query) +function api_request($query, $full_url = false) { $c = curl_init(); - curl_setopt($c, CURLOPT_URL, "https://api.github.com/$query"); + if ($full_url) + { + curl_setopt($c, CURLOPT_URL, $query); + } + else + { + curl_setopt($c, CURLOPT_URL, "https://api.github.com/$query?per_page=100"); + } curl_setopt($c, CURLOPT_RETURNTRANSFER, true); curl_setopt($c, CURLOPT_USERAGENT, 'phpBB/1.0'); + curl_setopt($c, CURLOPT_HEADER, true); $contents = curl_exec($c); curl_close($c); + $sub_request_result = array(); + if ($contents && strpos($contents, "\r\n\r\n") > 0) + { + list($header, $contents) = explode("\r\n\r\n", $contents); + foreach (explode("\n", $header) as $header_element) + { + if (strpos($header_element, 'Link') === 0) + { + list($head, $header_content) = explode(': ', $header_element); + foreach (explode(', ', $header_content) as $links) + { + list($url, $rel) = explode('; ', $links); + if ($rel == 'rel="next"') + { + $sub_request_result = api_request(substr($url, 1, -1), true); + } + } + } + } + } + if ($contents === false) { return false; } - return json_decode($contents); + $contents = json_decode($contents); + + if (isset($contents->message) && strpos($contents->message, 'API Rate Limit') === 0) + { + exit('Reached github API Rate Limit. Please try again later' . "\n"); + } + + return ($sub_request_result) ? array_merge($sub_request_result, $contents) : $contents; } function get_contributors($username, $repository) { - $request = api_request("repos/show/$username/$repository/contributors"); + $request = api_request("repos/$username/$repository/stats/contributors"); if ($request === false) { return false; } $usernames = array(); - foreach ($request->contributors as $contributor) + foreach ($request as $contribution) { - $usernames[$contributor->login] = $contributor->login; + $usernames[$contribution->author->login] = $contribution->author->login; } return $usernames; @@ -178,14 +214,14 @@ function get_contributors($username, $repository) function get_organisation_members($username) { - $request = api_request("organizations/$username/public_members"); + $request = api_request("orgs/$username/public_members"); if ($request === false) { return false; } $usernames = array(); - foreach ($request->users as $member) + foreach ($request as $member) { $usernames[$member->login] = $member->login; } @@ -195,16 +231,16 @@ function get_organisation_members($username) function get_collaborators($username, $repository) { - $request = api_request("repos/show/$username/$repository/collaborators"); + $request = api_request("repos/$username/$repository/collaborators"); if ($request === false) { return false; } $usernames = array(); - foreach ($request->collaborators as $collaborator) + foreach ($request as $collaborator) { - $usernames[$collaborator] = $collaborator; + $usernames[$collaborator->login] = $collaborator->login; } return $usernames; From 48f764437f3398696ad21177da02e024cc5804e5 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 13 Jun 2013 21:47:37 +0530 Subject: [PATCH 068/113] [ticket/10820] Add additional check for IE in condition PHPBB3-10820 --- phpBB/download/file.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index e06fd117cf..318e893fab 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -285,7 +285,7 @@ else if (($display_cat == ATTACHMENT_CATEGORY_NONE/* || $display_cat == ATTACHME $db->sql_query($sql); } -if ($display_cat == ATTACHMENT_CATEGORY_IMAGE && $mode === 'view' && (strpos($attachment['mimetype'], 'image') === 0) && !phpbb_is_greater_ie_version($user->browser, 7)) +if ($display_cat == ATTACHMENT_CATEGORY_IMAGE && $mode === 'view' && (strpos($attachment['mimetype'], 'image') === 0) && (strpos(strtolower($browser), 'msie') !== false) && !phpbb_is_greater_ie_version($user->browser, 7)) { wrap_img_in_html(append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'id=' . $attachment['attach_id']), $attachment['real_filename']); file_gc(); @@ -344,7 +344,7 @@ function send_avatar_to_browser($file, $browser) $image_data = @getimagesize($file_path); header('Content-Type: ' . image_type_to_mime_type($image_data[2])); - if (!phpbb_is_greater_ie_version($browser, 7)) + if ((strpos(strtolower($browser), 'msie') !== false) && !phpbb_is_greater_ie_version($browser, 7)) { header('Content-Disposition: attachment; ' . header_filename($file)); From 92c55ab111f5d28626975310fc93f35b3ca00ab0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 13 Jun 2013 18:41:23 +0200 Subject: [PATCH 069/113] [ticket/11603] Fix spacing and add some comments PHPBB3-11603 --- git-tools/setup_github_network.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index de3ea55d13..3f1f61b288 100755 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -156,17 +156,19 @@ function api_request($query, $full_url = false) } curl_setopt($c, CURLOPT_RETURNTRANSFER, true); curl_setopt($c, CURLOPT_USERAGENT, 'phpBB/1.0'); - curl_setopt($c, CURLOPT_HEADER, true); + curl_setopt($c, CURLOPT_HEADER, true); $contents = curl_exec($c); curl_close($c); $sub_request_result = array(); + // Split possible headers from the body if ($contents && strpos($contents, "\r\n\r\n") > 0) { list($header, $contents) = explode("\r\n\r\n", $contents); foreach (explode("\n", $header) as $header_element) { - if (strpos($header_element, 'Link') === 0) + // Find Link Header which gives us a link to the next page + if (strpos($header_element, 'Link: ') === 0) { list($head, $header_content) = explode(': ', $header_element); foreach (explode(', ', $header_content) as $links) @@ -174,6 +176,7 @@ function api_request($query, $full_url = false) list($url, $rel) = explode('; ', $links); if ($rel == 'rel="next"') { + // Found a next link, follow it and merge the results $sub_request_result = api_request(substr($url, 1, -1), true); } } From a7af0134c0cdd5577a094e78ddae258711591b10 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 13 Jun 2013 18:43:04 +0200 Subject: [PATCH 070/113] [ticket/11603] Split api_request into two functions (query only vs. full url) PHPBB3-11603 --- git-tools/setup_github_network.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index 3f1f61b288..c24968c7c2 100755 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -143,17 +143,15 @@ function get_repository_url($username, $repository, $ssh = false) return $url_base . $username . '/' . $repository . '.git'; } -function api_request($query, $full_url = false) +function api_request($query) +{ + return api_url_request("https://api.github.com/$query?per_page=100"); +} + +function api_url_request($url) { $c = curl_init(); - if ($full_url) - { - curl_setopt($c, CURLOPT_URL, $query); - } - else - { - curl_setopt($c, CURLOPT_URL, "https://api.github.com/$query?per_page=100"); - } + curl_setopt($c, CURLOPT_URL, $url); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); curl_setopt($c, CURLOPT_USERAGENT, 'phpBB/1.0'); curl_setopt($c, CURLOPT_HEADER, true); @@ -177,7 +175,7 @@ function api_request($query, $full_url = false) if ($rel == 'rel="next"') { // Found a next link, follow it and merge the results - $sub_request_result = api_request(substr($url, 1, -1), true); + $sub_request_result = api_url_request(substr($url, 1, -1)); } } } From de150cb4ad4b26ab51bcf60bd4377870e6b3866b Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 14 Jun 2013 00:29:06 +0530 Subject: [PATCH 071/113] [ticket/10820] fix if condition to check for IE PHPBB3-10820 --- phpBB/download/file.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 318e893fab..22be27c922 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -491,7 +491,7 @@ function send_file_to_browser($attachment, $upload_dir, $category) } else { - if (empty($user->browser) || !phpbb_is_greater_ie_version($user->browser, 7)) + if (empty($user->browser) || ((strpos(strtolower($user->browser), 'msie') !== false) && !phpbb_is_greater_ie_version($user->browser, 7))) { header('Content-Disposition: attachment; ' . header_filename(htmlspecialchars_decode($attachment['real_filename']))); if (empty($user->browser) || (strpos(strtolower($user->browser), 'msie 6.0') !== false)) From 50828e6d39259052fc728df9cb259ee664f6d751 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 15 Jun 2013 18:41:43 +0530 Subject: [PATCH 072/113] [ticket/11094] Add textbox for jabber while memberlist search PHPBB3-11094 --- phpBB/styles/prosilver/template/memberlist_search.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpBB/styles/prosilver/template/memberlist_search.html b/phpBB/styles/prosilver/template/memberlist_search.html index 9df648f644..e6a4bfba97 100644 --- a/phpBB/styles/prosilver/template/memberlist_search.html +++ b/phpBB/styles/prosilver/template/memberlist_search.html @@ -75,6 +75,10 @@ function insert_single(user)
      +
      +
      +
      +
      From 516581c41edaa5f565ef90bac14cdbdc054e7914 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 18 Jun 2013 15:04:48 +0200 Subject: [PATCH 073/113] [ticket/11604] Use variables for config.php filesnames. PHPBB3-11604 --- .../phpbb_functional_test_case.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 651ab013c7..1b47cbe125 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -184,15 +184,19 @@ class phpbb_functional_test_case extends phpbb_test_case self::$config['table_prefix'] = 'phpbb_'; self::recreate_database(self::$config); - if (file_exists($phpbb_root_path . "config.$phpEx")) + $config_file = $phpbb_root_path . "config.$phpEx"; + $config_file_dev = $phpbb_root_path . "config_dev.$phpEx"; + $config_file_test = $phpbb_root_path . "config_test.$phpEx"; + + if (file_exists($config_file)) { - if (!file_exists($phpbb_root_path . "config_dev.$phpEx")) + if (!file_exists($config_file_dev)) { - rename($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_dev.$phpEx"); + rename($config_file, $config_file_dev); } else { - unlink($phpbb_root_path . "config.$phpEx"); + unlink($config_file); } } @@ -254,7 +258,7 @@ class phpbb_functional_test_case extends phpbb_test_case $crawler = self::submit($form); self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); - file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true)); + file_put_contents($config_file, phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true)); $form = $crawler->selectButton('submit')->form(); $crawler = self::submit($form); @@ -281,7 +285,7 @@ class phpbb_functional_test_case extends phpbb_test_case $crawler = self::submit($form); self::assertContains('You have successfully installed', $crawler->text()); - copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); + copy($config_file, $config_file_test); } static private function recreate_database($config) From 21f839494ddb55d1c4aefeed113b5debe9b2e1b3 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 18 Jun 2013 15:21:28 +0200 Subject: [PATCH 074/113] [ticket/11604] Fix case where config.php is not generated by phpBB. PHPBB3-11604 --- .../phpbb_functional_test_case.php | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 1b47cbe125..16ed9f5a1e 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -257,8 +257,30 @@ class phpbb_functional_test_case extends phpbb_test_case $form = $crawler->selectButton('submit')->form(); $crawler = self::submit($form); + $config_writable = strpos($crawler->filter('#main')->text(), 'It was not possible to write the configuration file.') === false; + $config_php_data = phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true); + + if (!$config_writable) + { + // phpBB could not write to the config.php file, so we have to "Download" it. + self::assertContains('Download config', $crawler->filter('#main')->text()); + + file_put_contents($config_file, $config_php_data); + + $form = $crawler->selectButton('dldone')->form(); + $crawler = self::submit($form); + } + self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); - file_put_contents($config_file, phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true)); + + // Overwrite the config.php file generated by phpBB in order to get the + // DEBUG constants defined if possible. It should be possible when unit + // tests run as the same user as phpBB. + if ($config_writable && is_writable($config_file)) + { + file_put_contents($config_file, $config_php_data); + } + $form = $crawler->selectButton('submit')->form(); $crawler = self::submit($form); From 1516ae7e7ed77879506a32f00c9787b95106235d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 19 Jun 2013 13:38:03 +0200 Subject: [PATCH 075/113] [ticket/11603] Avoid using cURL PHPBB3-11603 --- git-tools/merge.php | 17 ++++++++++------- git-tools/setup_github_network.php | 21 +++++++++------------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/git-tools/merge.php b/git-tools/merge.php index 5eb48a53f8..08c0ecfbd0 100755 --- a/git-tools/merge.php +++ b/git-tools/merge.php @@ -124,13 +124,16 @@ function get_repository_url($username, $repository, $ssh = false) function api_request($query) { - $c = curl_init(); - curl_setopt($c, CURLOPT_URL, "https://api.github.com/$query"); - curl_setopt($c, CURLOPT_RETURNTRANSFER, true); - curl_setopt($c, CURLOPT_USERAGENT, 'phpBB/1.0'); - curl_setopt($c, CURLOPT_HEADER, true); - $contents = curl_exec($c); - curl_close($c); + return api_url_request("https://api.github.com/$query?per_page=100"); +} + +function api_url_request($url) +{ + $contents = file_get_contents($url, false, stream_context_create(array( + 'http' => array( + 'header' => "User-Agent: phpBB/1.0\r\n", + ), + ))); if ($contents === false) { diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index c24968c7c2..e5bc89bf91 100755 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -150,21 +150,18 @@ function api_request($query) function api_url_request($url) { - $c = curl_init(); - curl_setopt($c, CURLOPT_URL, $url); - curl_setopt($c, CURLOPT_RETURNTRANSFER, true); - curl_setopt($c, CURLOPT_USERAGENT, 'phpBB/1.0'); - curl_setopt($c, CURLOPT_HEADER, true); - $contents = curl_exec($c); - curl_close($c); + $contents = file_get_contents($url, false, stream_context_create(array( + 'http' => array( + 'header' => "User-Agent: phpBB/1.0\r\n", + ), + ))); $sub_request_result = array(); // Split possible headers from the body - if ($contents && strpos($contents, "\r\n\r\n") > 0) + if (!empty($http_response_header)) { - list($header, $contents) = explode("\r\n\r\n", $contents); - foreach (explode("\n", $header) as $header_element) - { + foreach ($http_response_header as $header_element) + { // Find Link Header which gives us a link to the next page if (strpos($header_element, 'Link: ') === 0) { @@ -179,7 +176,7 @@ function api_url_request($url) } } } - } + } } if ($contents === false) From 99e486dc8234d28aae1e9c3ed108f0b78d0033f0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 19 Jun 2013 13:45:42 +0200 Subject: [PATCH 076/113] [ticket/11603] Throw RuntimeExceptions instead of using exit() PHPBB3-11603 --- git-tools/merge.php | 2 +- git-tools/setup_github_network.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/git-tools/merge.php b/git-tools/merge.php index 08c0ecfbd0..f6142095fb 100755 --- a/git-tools/merge.php +++ b/git-tools/merge.php @@ -143,7 +143,7 @@ function api_url_request($url) if (isset($contents->message) && strpos($contents->message, 'API Rate Limit') === 0) { - exit('Reached github API Rate Limit. Please try again later' . "\n"); + throw new RuntimeException('Reached github API Rate Limit. Please try again later' . "\n", 4); } return $contents; diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index e5bc89bf91..bc85d67ab5 100755 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -187,7 +187,7 @@ function api_url_request($url) if (isset($contents->message) && strpos($contents->message, 'API Rate Limit') === 0) { - exit('Reached github API Rate Limit. Please try again later' . "\n"); + throw new RuntimeException('Reached github API Rate Limit. Please try again later' . "\n", 4); } return ($sub_request_result) ? array_merge($sub_request_result, $contents) : $contents; From 1af6dc22e2ccb13b610a932a9b043d2d9d4ea17d Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 19 Jun 2013 17:03:41 +0200 Subject: [PATCH 077/113] [ticket/11604] Skip installer step where config.php is created. PHPBB3-11604 --- .../phpbb_functional_test_case.php | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 16ed9f5a1e..6b423b56fd 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -220,10 +220,12 @@ class phpbb_functional_test_case extends phpbb_test_case self::assertContains('Welcome to Installation', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); + // install/index.php?mode=install&sub=requirements $crawler = self::submit($form); self::assertContains('Installation compatibility', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); + // install/index.php?mode=install&sub=database $crawler = self::submit($form); self::assertContains('Database configuration', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( @@ -237,10 +239,12 @@ class phpbb_functional_test_case extends phpbb_test_case 'table_prefix' => self::$config['table_prefix'], )); + // install/index.php?mode=install&sub=database $crawler = self::submit($form); self::assertContains('Successful connection', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); + // install/index.php?mode=install&sub=administrator $crawler = self::submit($form); self::assertContains('Administrator configuration', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( @@ -252,38 +256,38 @@ class phpbb_functional_test_case extends phpbb_test_case 'board_email2' => 'nobody@example.com', )); + // install/index.php?mode=install&sub=administrator $crawler = self::submit($form); self::assertContains('Tests passed', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::submit($form); - $config_writable = strpos($crawler->filter('#main')->text(), 'It was not possible to write the configuration file.') === false; + // We have to skip install/index.php?mode=install&sub=config_file + // because that step will create a config.php file if phpBB has the + // permission to do so. We have to create the config file on our own + // in order to get the DEBUG constants defined. $config_php_data = phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true); - - if (!$config_writable) + $config_created = file_put_contents($config_file, $config_php_data) !== false; + if (!$config_created) { - // phpBB could not write to the config.php file, so we have to "Download" it. - self::assertContains('Download config', $crawler->filter('#main')->text()); - - file_put_contents($config_file, $config_php_data); - - $form = $crawler->selectButton('dldone')->form(); - $crawler = self::submit($form); + self::markTestSkipped("Could not write $config_file file."); } - self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); - - // Overwrite the config.php file generated by phpBB in order to get the - // DEBUG constants defined if possible. It should be possible when unit - // tests run as the same user as phpBB. - if ($config_writable && is_writable($config_file)) + // We also have to create a install lock that is normally created by + // the installer. The file will be removed by the final step of the + // installer. + $install_lock_file = $phpbb_root_path . 'cache/install_lock'; + $lock_created = file_put_contents($install_lock_file, '') !== false; + if (!$lock_created) { - file_put_contents($config_file, $config_php_data); + self::markTestSkipped("Could not create $lock_created file."); } + @chmod($install_lock_file, 0666); - $form = $crawler->selectButton('submit')->form(); + // install/index.php?mode=install&sub=advanced + $form_data = $form->getValues(); + unset($form_data['submit']); - $crawler = self::submit($form); + $crawler = self::request('POST', 'install/index.php?mode=install&sub=advanced', $form_data); self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( 'email_enable' => true, @@ -300,13 +304,16 @@ class phpbb_functional_test_case extends phpbb_test_case 'script_path' => $parseURL['path'], )); + // install/index.php?mode=install&sub=create_table $crawler = self::submit($form); self::assertContains('The database tables used by phpBB', $crawler->filter('#main')->text()); self::assertContains('have been created and populated with some initial data.', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); + // install/index.php?mode=install&sub=final $crawler = self::submit($form); self::assertContains('You have successfully installed', $crawler->text()); + copy($config_file, $config_file_test); } From 5f4daba160ccfe028862239613be880545437a16 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 20 Jun 2013 10:57:56 +0200 Subject: [PATCH 078/113] [ticket/11603] Fix usage note PHPBB3-11603 --- git-tools/setup_github_network.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index bc85d67ab5..e8417c91d2 100755 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -15,7 +15,7 @@ function show_usage() echo "$filename adds repositories of a github network as remotes to a local git repository.\n"; echo "\n"; - echo "Usage: [php] $filename -s collaborators|organisation|contributors|network [OPTIONS]\n"; + echo "Usage: [php] $filename -s collaborators|organisation|contributors|forks [OPTIONS]\n"; echo "\n"; echo "Scopes:\n"; From b362fb44d20b387f6a4ba6b6e33ebd387096be18 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 20 Jun 2013 10:59:43 +0200 Subject: [PATCH 079/113] [ticket/11603] Fix out dated comment PHPBB3-11603 --- git-tools/setup_github_network.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-tools/setup_github_network.php b/git-tools/setup_github_network.php index e8417c91d2..4e144edae6 100755 --- a/git-tools/setup_github_network.php +++ b/git-tools/setup_github_network.php @@ -157,7 +157,7 @@ function api_url_request($url) ))); $sub_request_result = array(); - // Split possible headers from the body + // Check headers for pagination links if (!empty($http_response_header)) { foreach ($http_response_header as $header_element) From 6cbb2d6136dc702e8d07eb53b24a026238768841 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 21 Jun 2013 18:24:06 +0530 Subject: [PATCH 080/113] [ticket/10776] update min php version 5.3.3 in readme PHPBB3-10776 --- phpBB/docs/README.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/docs/README.html b/phpBB/docs/README.html index bf72ce1d1f..81ce736df7 100644 --- a/phpBB/docs/README.html +++ b/phpBB/docs/README.html @@ -325,7 +325,7 @@
      -

      phpBB is no longer supported on PHP3 due to several compatibility issues and we recommend that you upgrade to the latest stable release of PHP5 to run phpBB. The minimum version required is PHP 4.3.3. The minimum version that will be required for phpBB 3.1 is PHP 5.3.2.

      +

      phpBB is no longer supported on PHP3 due to several compatibility issues and we recommend that you upgrade to the latest stable release of PHP5 to run phpBB. The minimum version required is PHP 4.3.3. The minimum version that will be required for phpBB 3.1 is PHP 5.3.3.

      Please remember that running any application on a development (unstable, e.g. a beta release) version of PHP can lead to strange/unexpected results which may appear to be bugs in the application. Therefore, we recommend you upgrade to the newest stable version of PHP before running phpBB3. If you are running a development version of PHP please check any bugs you find on a system running a stable release before submitting.

      From a105a6d7a7140fe94e9b0a166fa515b9e02d9e3e Mon Sep 17 00:00:00 2001 From: Andy Chase Date: Tue, 25 Jun 2013 12:39:43 -0700 Subject: [PATCH 081/113] [ticket/11615] Rename init_test to creation_test for clarity PHPBB3-11615 --- tests/session/{init_test.php => creation_test.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/session/{init_test.php => creation_test.php} (100%) diff --git a/tests/session/init_test.php b/tests/session/creation_test.php similarity index 100% rename from tests/session/init_test.php rename to tests/session/creation_test.php From c29cca1a755461ec2bd63b7cc9292d79ae0508d6 Mon Sep 17 00:00:00 2001 From: Andy Chase Date: Tue, 25 Jun 2013 12:40:31 -0700 Subject: [PATCH 082/113] [ticket/11615] Rename class in file to match PHPBB3-11615 --- tests/session/creation_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/session/creation_test.php b/tests/session/creation_test.php index 2ce6c4a4ac..c5558c1577 100644 --- a/tests/session/creation_test.php +++ b/tests/session/creation_test.php @@ -10,7 +10,7 @@ require_once dirname(__FILE__) . '/../mock/cache.php'; require_once dirname(__FILE__) . '/testable_factory.php'; -class phpbb_session_init_test extends phpbb_database_test_case +class phpbb_session_creation_test extends phpbb_database_test_case { public function getDataSet() { From 4c432fecc75473c5f12a70048973a4139bdf1b22 Mon Sep 17 00:00:00 2001 From: Andy Chase Date: Tue, 25 Jun 2013 12:42:19 -0700 Subject: [PATCH 083/113] [ticket/11615] Remove magic number in creation_test Removing this magic number to its own variable with clean multiplication makes it clear what the number represents. PHPBB3-11615 --- tests/session/creation_test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/session/creation_test.php b/tests/session/creation_test.php index c5558c1577..b9f8b18c63 100644 --- a/tests/session/creation_test.php +++ b/tests/session/creation_test.php @@ -38,7 +38,8 @@ class phpbb_session_creation_test extends phpbb_database_test_case 'Check if exacly one session for user id 3 was created' ); - $cookie_expire = $session->time_now + 31536000; // default is one year + $one_year_in_seconds = 365 * 24 * 60 * 60; + $cookie_expire = $session->time_now + $one_year_in_seconds; $session->check_cookies($this, array( 'u' => array(null, $cookie_expire), From 7ba81a293f014f3c6b161672b8fbc27e2075d239 Mon Sep 17 00:00:00 2001 From: Andy Chase Date: Tue, 25 Jun 2013 12:42:41 -0700 Subject: [PATCH 084/113] [ticket/11615] Fix typo in creation_test PHPBB3-11615 --- tests/session/creation_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/session/creation_test.php b/tests/session/creation_test.php index b9f8b18c63..bef52c6554 100644 --- a/tests/session/creation_test.php +++ b/tests/session/creation_test.php @@ -35,7 +35,7 @@ class phpbb_session_creation_test extends phpbb_database_test_case $this->assertSqlResultEquals( array(array('session_user_id' => 3)), $sql, - 'Check if exacly one session for user id 3 was created' + 'Check if exactly one session for user id 3 was created' ); $one_year_in_seconds = 365 * 24 * 60 * 60; From fe4bfd02a3f3b178130c7a8d8bcf66a4ab1c67d4 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 23 Jun 2013 21:37:54 +0530 Subject: [PATCH 085/113] [ticket/10838] Updated RUNNING_TESTS.md PHPBB3-10838 --- tests/RUNNING_TESTS.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md index 26a93f0430..bde1455855 100644 --- a/tests/RUNNING_TESTS.md +++ b/tests/RUNNING_TESTS.md @@ -114,6 +114,42 @@ only want the slow tests, run: $ phpBB/vendor/bin/phpunit --group slow +Functional tests +----------------- + +Functional tests test software the way a user would. They simulate a user +browsing the website, but they do these steps in an automated way. +phpBB allows you to write such tests. This document will tell you how. + +Running +======= + +Running the tests requires your phpBB3 repository to be accessible through a +local web server. As of PHP 5.4 a builtin webserver is available. If you are +on PHP 5.3 you will also need to supply the URL to a webserver of your own in +the 'tests/test_config.php' file. This is as simple as defining the +'$phpbb_functional_url', which contains the URL for the directory containing +the board. Make sure you include the trailing slash. Testing makes use of a +seperate database defined in this config file and before running the tests +each time this database is deleted. Note that without extensive changes to the +test framework, you cannot use a board outside of the repository on which to +run tests. + + $phpbb_functional_url = 'http://localhost/phpBB3/'; + +On PHP 5.4 you do not need the $phpbb_functional_url parameter but you can +configure the port the builtin webserver runs on using + + $phpbb_functional_port = 8000; + +To then run the tests, you run PHPUnit, but use the phpunit.xml.functional +config file instead of the default one. Specify this through the "-c" option: + + phpunit -c phpunit.xml.functional + +This will change your board's config.php file, but it makes a backup at +config_dev.php, so you can restore it after the test run is complete. + More Information ================ From 8e575487ff73f3b9c05aceba7b71f06c6e0b032a Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Wed, 26 Jun 2013 19:51:52 -0400 Subject: [PATCH 086/113] [ticket/11618] Replace glob() with scandir() and string matching Removes glob from template tests as glob() does not work on all systems according to PHP documentation as has been noticed by users. PHPBB3-11618 --- tests/template/template_test.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/template/template_test.php b/tests/template/template_test.php index e532de294c..fd68124c89 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -69,9 +69,14 @@ class phpbb_template_template_test extends phpbb_test_case $this->markTestSkipped("Template cache directory ({$template_cache_dir}) is not writable."); } - foreach (glob($this->template->cachepath . '*') as $file) + $file_array = scandir($template_cache_dir); + $file_prefix = basename($this->template->cachepath); + foreach ($file_array as $file) { - unlink($file); + if (strpos($file, $file_prefix) === 0) + { + unlink($template_cache_dir . '/' . $file); + } } $GLOBALS['config'] = array( @@ -84,9 +89,15 @@ class phpbb_template_template_test extends phpbb_test_case { if (is_object($this->template)) { - foreach (glob($this->template->cachepath . '*') as $file) + $template_cache_dir = dirname($this->template->cachepath); + $file_array = scandir($template_cache_dir); + $file_prefix = basename($this->template->cachepath); + foreach ($file_array as $file) { - unlink($file); + if (strpos($file, $file_prefix) === 0) + { + unlink($template_cache_dir . '/' . $file); + } } } } From 7a2e3b4354b495f7f46bc57dfde070ce7270bd25 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 3 Jun 2013 23:38:48 +0530 Subject: [PATCH 087/113] [ticket/11566] add interface for captcha Add basic captcha template while reporting post when the user is not a registered user. PHPBB3-11566 --- phpBB/report.php | 14 ++++++++++++++ phpBB/styles/prosilver/template/report_body.html | 3 +++ 2 files changed, 17 insertions(+) diff --git a/phpBB/report.php b/phpBB/report.php index c1172ec1d5..06fc086d4d 100644 --- a/phpBB/report.php +++ b/phpBB/report.php @@ -133,6 +133,13 @@ else } } +if ($config['enable_post_confirm'] && !$user->data['is_registered']) +{ + include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx); + $captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']); + $captcha->init(CONFIRM_POST); +} + // Submit report? if ($submit && $reason_id) { @@ -224,6 +231,13 @@ display_reasons($reason_id); $page_title = ($pm_id) ? $user->lang['REPORT_MESSAGE'] : $user->lang['REPORT_POST']; +if ($config['enable_post_confirm'] && !$user->data['is_registered'] && (isset($captcha) && $captcha->is_solved() === false)) +{ + $template->assign_vars(array( + 'CAPTCHA_TEMPLATE' => $captcha->get_template(), + )); +} + $template->assign_vars(array( 'S_REPORT_POST' => ($pm_id) ? false : true, 'REPORT_TEXT' => $report_text, diff --git a/phpBB/styles/prosilver/template/report_body.html b/phpBB/styles/prosilver/template/report_body.html index b0c6e08049..8bf639791b 100644 --- a/phpBB/styles/prosilver/template/report_body.html +++ b/phpBB/styles/prosilver/template/report_body.html @@ -27,6 +27,9 @@

      {L_CAN_LEAVE_BLANK}
      + + +
      From eafd0ae29f649213cf71b7575131b7f5555c4e67 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 10 Jun 2013 23:52:41 +0530 Subject: [PATCH 088/113] [ticket/11566] add error functionality add $error which stores the captcha error when captcha validation fails PHPBB3-11566 --- phpBB/report.php | 149 ++++++++++++++++++++++++++--------------------- 1 file changed, 81 insertions(+), 68 deletions(-) diff --git a/phpBB/report.php b/phpBB/report.php index 06fc086d4d..7f6cd4a792 100644 --- a/phpBB/report.php +++ b/phpBB/report.php @@ -140,90 +140,101 @@ if ($config['enable_post_confirm'] && !$user->data['is_registered']) $captcha->init(CONFIRM_POST); } +$error = array(); + // Submit report? if ($submit && $reason_id) { - $sql = 'SELECT * - FROM ' . REPORTS_REASONS_TABLE . " - WHERE reason_id = $reason_id"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$row || (!$report_text && strtolower($row['reason_title']) == 'other')) + $vc_response = $captcha->validate(); + if ($vc_response) { - trigger_error('EMPTY_REPORT'); + $error[] = $vc_response; } - $sql_ary = array( - 'reason_id' => (int) $reason_id, - 'post_id' => $post_id, - 'pm_id' => $pm_id, - 'user_id' => (int) $user->data['user_id'], - 'user_notify' => (int) $user_notify, - 'report_closed' => 0, - 'report_time' => (int) time(), - 'report_text' => (string) $report_text - ); - - $sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - $report_id = $db->sql_nextid(); - - if ($post_id) + if (!sizeof($error)) { - $sql = 'UPDATE ' . POSTS_TABLE . ' - SET post_reported = 1 - WHERE post_id = ' . $post_id; - $db->sql_query($sql); + $sql = 'SELECT * + FROM ' . REPORTS_REASONS_TABLE . " + WHERE reason_id = $reason_id"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); - if (!$report_data['topic_reported']) + if (!$row || (!$report_text && strtolower($row['reason_title']) == 'other')) { - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_reported = 1 - WHERE topic_id = ' . $report_data['topic_id'] . ' - OR topic_moved_id = ' . $report_data['topic_id']; - $db->sql_query($sql); + trigger_error('EMPTY_REPORT'); } - $lang_return = $user->lang['RETURN_TOPIC']; - $lang_success = $user->lang['POST_REPORTED_SUCCESS']; - } - else - { - $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' - SET message_reported = 1 - WHERE msg_id = ' . $pm_id; - $db->sql_query($sql); - $sql_ary = array( - 'msg_id' => $pm_id, - 'user_id' => ANONYMOUS, - 'author_id' => (int) $report_data['author_id'], - 'pm_deleted' => 0, - 'pm_new' => 0, - 'pm_unread' => 0, - 'pm_replied' => 0, - 'pm_marked' => 0, - 'pm_forwarded' => 0, - 'folder_id' => PRIVMSGS_INBOX, + 'reason_id' => (int) $reason_id, + 'post_id' => $post_id, + 'pm_id' => $pm_id, + 'user_id' => (int) $user->data['user_id'], + 'user_notify' => (int) $user_notify, + 'report_closed' => 0, + 'report_time' => (int) time(), + 'report_text' => (string) $report_text ); - $sql = 'INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); $db->sql_query($sql); + $report_id = $db->sql_nextid(); - $lang_return = $user->lang['RETURN_PM']; - $lang_success = $user->lang['PM_REPORTED_SUCCESS']; + if ($post_id) + { + $sql = 'UPDATE ' . POSTS_TABLE . ' + SET post_reported = 1 + WHERE post_id = ' . $post_id; + $db->sql_query($sql); + + if (!$report_data['topic_reported']) + { + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET topic_reported = 1 + WHERE topic_id = ' . $report_data['topic_id'] . ' + OR topic_moved_id = ' . $report_data['topic_id']; + $db->sql_query($sql); + } + + $lang_return = $user->lang['RETURN_TOPIC']; + $lang_success = $user->lang['POST_REPORTED_SUCCESS']; + } + else + { + $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' + SET message_reported = 1 + WHERE msg_id = ' . $pm_id; + $db->sql_query($sql); + + $sql_ary = array( + 'msg_id' => $pm_id, + 'user_id' => ANONYMOUS, + 'author_id' => (int) $report_data['author_id'], + 'pm_deleted' => 0, + 'pm_new' => 0, + 'pm_unread' => 0, + 'pm_replied' => 0, + 'pm_marked' => 0, + 'pm_forwarded' => 0, + 'folder_id' => PRIVMSGS_INBOX, + ); + + $sql = 'INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + + $lang_return = $user->lang['RETURN_PM']; + $lang_success = $user->lang['PM_REPORTED_SUCCESS']; + } + + meta_refresh(3, $redirect_url); + + $message = $lang_success . '

      ' . sprintf($lang_return, '', ''); + if ($return_forum_url) + { + $message .= '

      ' . sprintf($user->lang['RETURN_FORUM'], '', ''); + } + trigger_error($message); } - - meta_refresh(3, $redirect_url); - - $message = $lang_success . '

      ' . sprintf($lang_return, '', ''); - if ($return_forum_url) - { - $message .= '

      ' . sprintf($user->lang['RETURN_FORUM'], '', ''); - } - trigger_error($message); } // Generate the reasons @@ -231,14 +242,16 @@ display_reasons($reason_id); $page_title = ($pm_id) ? $user->lang['REPORT_MESSAGE'] : $user->lang['REPORT_POST']; -if ($config['enable_post_confirm'] && !$user->data['is_registered'] && (isset($captcha) && $captcha->is_solved() === false)) +if ((isset($captcha) && $captcha->is_solved() === false)) { $template->assign_vars(array( + 'S_CONFIRM_CODE' => true, 'CAPTCHA_TEMPLATE' => $captcha->get_template(), )); } $template->assign_vars(array( + 'ERROR' => (sizeof($error)) ? implode('
      ', $error) : '', 'S_REPORT_POST' => ($pm_id) ? false : true, 'REPORT_TEXT' => $report_text, 'S_REPORT_ACTION' => append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&p=' . $post_id . '&pm=' . $pm_id), From 7c9a1cbca9719eccbee11db418cb4e531f539a0c Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 10 Jun 2013 23:53:33 +0530 Subject: [PATCH 089/113] [ticket/11566] add error in template Check if error exists, then display it in the report post template. PHPBB3-11566 --- phpBB/styles/prosilver/template/report_body.html | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/styles/prosilver/template/report_body.html b/phpBB/styles/prosilver/template/report_body.html index 8bf639791b..2d6a857afb 100644 --- a/phpBB/styles/prosilver/template/report_body.html +++ b/phpBB/styles/prosilver/template/report_body.html @@ -10,6 +10,7 @@

      {L_REPORT_POST_EXPLAIN}{L_REPORT_MESSAGE_EXPLAIN}

      +
      {ERROR}
      From 2c240f8a7b36feab129336b7e36273cdb9798364 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Tue, 11 Jun 2013 00:09:14 +0530 Subject: [PATCH 090/113] [ticket/11566] display error instead of trigger_error When the error report is empty display error in the template instead of trigger_error PHPBB3-11566 --- phpBB/report.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/phpBB/report.php b/phpBB/report.php index 7f6cd4a792..1ae0abcdc2 100644 --- a/phpBB/report.php +++ b/phpBB/report.php @@ -151,20 +151,20 @@ if ($submit && $reason_id) $error[] = $vc_response; } + $sql = 'SELECT * + FROM ' . REPORTS_REASONS_TABLE . " + WHERE reason_id = $reason_id"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (!$row || (!$report_text && strtolower($row['reason_title']) == 'other')) + { + $error[] = $user->lang('EMPTY_REPORT'); + } + if (!sizeof($error)) { - $sql = 'SELECT * - FROM ' . REPORTS_REASONS_TABLE . " - WHERE reason_id = $reason_id"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$row || (!$report_text && strtolower($row['reason_title']) == 'other')) - { - trigger_error('EMPTY_REPORT'); - } - $sql_ary = array( 'reason_id' => (int) $reason_id, 'post_id' => $post_id, From c4fbed251db058d808823d2700c441383edc3e63 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Tue, 11 Jun 2013 00:20:26 +0530 Subject: [PATCH 091/113] [ticket/11566] add captcha reset and hidden fields If captcha is solved and some other error pops up, store the captcha in a hidden field. Reset captcha if reporting the post is successful PHPBB3-11566 --- phpBB/report.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/phpBB/report.php b/phpBB/report.php index 1ae0abcdc2..b876b5c94f 100644 --- a/phpBB/report.php +++ b/phpBB/report.php @@ -141,6 +141,7 @@ if ($config['enable_post_confirm'] && !$user->data['is_registered']) } $error = array(); +$s_hidden_fields = ''; // Submit report? if ($submit && $reason_id) @@ -165,6 +166,11 @@ if ($submit && $reason_id) if (!sizeof($error)) { + if (isset($captcha)) + { + $captcha->reset(); + } + $sql_ary = array( 'reason_id' => (int) $reason_id, 'post_id' => $post_id, @@ -235,6 +241,10 @@ if ($submit && $reason_id) } trigger_error($message); } + else if (isset($captcha) && $captcha->is_solved() !== false) + { + $s_hidden_fields .= build_hidden_fields($captcha->get_hidden_fields()); + } } // Generate the reasons @@ -255,6 +265,7 @@ $template->assign_vars(array( 'S_REPORT_POST' => ($pm_id) ? false : true, 'REPORT_TEXT' => $report_text, 'S_REPORT_ACTION' => append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&p=' . $post_id . '&pm=' . $pm_id), + 'S_HIDDEN_FIELDS' => (sizeof($s_hidden_fields)) ? $s_hidden_fields : null, 'S_NOTIFY' => $user_notify, 'S_CAN_NOTIFY' => ($user->data['is_registered']) ? true : false) From 43053c541ac0f998a3925b7277cfb77f1ceafb11 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 12 Jun 2013 01:45:07 +0530 Subject: [PATCH 092/113] [ticket/11566] add tests for reporting post Functional test for reporting post and check if captcha validation is required for guests and not for registerted users PHPBB3-11566 --- tests/functional/report_post_captcha.php | 55 ++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/functional/report_post_captcha.php diff --git a/tests/functional/report_post_captcha.php b/tests/functional/report_post_captcha.php new file mode 100644 index 0000000000..6b112c3538 --- /dev/null +++ b/tests/functional/report_post_captcha.php @@ -0,0 +1,55 @@ +login(); + $crawler = self::request('GET', 'report.php?f=2&p=1'); + $this->assertNotContains($this->lang('CONFIRM_CODE'), $crawler->filter('html')->text()); + } + + public function test_guest_report_post() + { + $this->enable_reporting_guest(); + $crawler = self::request('GET', 'report.php?f=2&p=1'); + $this->assertContains($this->lang('CONFIRM_CODE'), $crawler->filter('html')->text()); + } + + protected function enable_reporting_guest() + { + $this->login(); + $this->admin_login(); + + $crawler = self::request('GET', 'adm/index.php?i=permissions&icat=12&mode=setting_group_local&sid=' . $this->sid); + $form = $crawler->selectButton('Submit')->form(); + $values = $form->getValues(); + $values["group_id[0]"] = 1; + $form->setValues($values); + $crawler = self::submit($form); + + $form = $crawler->selectButton('Submit')->form(); + $values = $form->getValues(); + $values["forum_id"] = 2; + $form->setValues($values); + $crawler = self::submit($form); + + $form = $crawler->selectButton('Apply all permissions')->form(); + $values = $form->getValues(); + $values["setting[1][2][f_report]"] = 1; + $form->setValues($values); + $crawler = self::submit($form); + + $crawler = self::request('GET', 'ucp.php?mode=logout&sid=' . $this->sid); + } +} From 1abc3d91d05919f20b31876dbafbb8edec83d724 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 12 Jun 2013 02:00:24 +0530 Subject: [PATCH 093/113] [ticket/11566] Use language variable instead of hardcode Add language variable in tests PHPBB3-11566 --- tests/functional/report_post_captcha.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/functional/report_post_captcha.php b/tests/functional/report_post_captcha.php index 6b112c3538..e0a67ab6fa 100644 --- a/tests/functional/report_post_captcha.php +++ b/tests/functional/report_post_captcha.php @@ -44,7 +44,8 @@ class phpbb_functional_report_post_captcha_test extends phpbb_functional_test_ca $form->setValues($values); $crawler = self::submit($form); - $form = $crawler->selectButton('Apply all permissions')->form(); + $this->add_lang('acp/permissions'); + $form = $crawler->selectButton($this->lang('APPLY_ALL_PERMISSIONS'))->form(); $values = $form->getValues(); $values["setting[1][2][f_report]"] = 1; $form->setValues($values); From 434d14e1d5c2341584c9d5cfd93840f3eb1a6941 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 12 Jun 2013 20:00:51 +0530 Subject: [PATCH 094/113] [ticket/11566] Revert forum permission changes Revert the f_report permission for guests in the functional tests PHPBB3-11566 --- tests/functional/report_post_captcha.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/functional/report_post_captcha.php b/tests/functional/report_post_captcha.php index e0a67ab6fa..0585be1332 100644 --- a/tests/functional/report_post_captcha.php +++ b/tests/functional/report_post_captcha.php @@ -21,12 +21,13 @@ class phpbb_functional_report_post_captcha_test extends phpbb_functional_test_ca public function test_guest_report_post() { - $this->enable_reporting_guest(); + $this->set_reporting_guest(1); $crawler = self::request('GET', 'report.php?f=2&p=1'); $this->assertContains($this->lang('CONFIRM_CODE'), $crawler->filter('html')->text()); + $this->set_reporting_guest(-1); } - protected function enable_reporting_guest() + protected function set_reporting_guest($report_post_allowed) { $this->login(); $this->admin_login(); @@ -47,7 +48,7 @@ class phpbb_functional_report_post_captcha_test extends phpbb_functional_test_ca $this->add_lang('acp/permissions'); $form = $crawler->selectButton($this->lang('APPLY_ALL_PERMISSIONS'))->form(); $values = $form->getValues(); - $values["setting[1][2][f_report]"] = 1; + $values["setting[1][2][f_report]"] = $report_post_allowed; $form->setValues($values); $crawler = self::submit($form); From 88b5180aa11ba90f37d598737bb46a054382042f Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 22 Jun 2013 03:54:21 +0530 Subject: [PATCH 095/113] [ticket/11566] Rename var to $visual_confirmation_response PHPBB3-11566 --- phpBB/report.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/report.php b/phpBB/report.php index b876b5c94f..4fecaf4046 100644 --- a/phpBB/report.php +++ b/phpBB/report.php @@ -146,10 +146,10 @@ $s_hidden_fields = ''; // Submit report? if ($submit && $reason_id) { - $vc_response = $captcha->validate(); - if ($vc_response) + $visual_confirmation_response = $captcha->validate(); + if ($visual_confirmation_response) { - $error[] = $vc_response; + $error[] = $visual_confirmation_response; } $sql = 'SELECT * From 4ad1d9aa6530ebe1d554909a978b9ee124377625 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 22 Jun 2013 04:07:21 +0530 Subject: [PATCH 096/113] [ticket/11566] Use the new constant CONFIRM_REPORT for captcha init PHPBB3-11566 --- phpBB/includes/constants.php | 1 + phpBB/report.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index 17c25ee3c6..ad5b43bc9a 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -157,6 +157,7 @@ define('PHYSICAL_LINK', 2); define('CONFIRM_REG', 1); define('CONFIRM_LOGIN', 2); define('CONFIRM_POST', 3); +define('CONFIRM_REPORT', 4); // Categories - Attachments define('ATTACHMENT_CATEGORY_NONE', 0); diff --git a/phpBB/report.php b/phpBB/report.php index 4fecaf4046..f89a18fa8e 100644 --- a/phpBB/report.php +++ b/phpBB/report.php @@ -137,7 +137,7 @@ if ($config['enable_post_confirm'] && !$user->data['is_registered']) { include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx); $captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']); - $captcha->init(CONFIRM_POST); + $captcha->init(CONFIRM_REPORT); } $error = array(); From ea8a4abe66b7142fd8b16dc9732bac181031875a Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 23 Jun 2013 21:47:42 +0530 Subject: [PATCH 097/113] [ticket/11566] Add captcha to report post template in subsilver PHPBB3-11566 --- phpBB/styles/subsilver2/template/report_body.html | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/phpBB/styles/subsilver2/template/report_body.html b/phpBB/styles/subsilver2/template/report_body.html index 7cd7d1040f..1653875799 100644 --- a/phpBB/styles/subsilver2/template/report_body.html +++ b/phpBB/styles/subsilver2/template/report_body.html @@ -3,6 +3,11 @@
      + + + + + @@ -25,6 +30,9 @@ + + + From 84ec1f542365d38763b099e0cb9dcc78cc341258 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 1 Jul 2013 01:34:21 +0530 Subject: [PATCH 098/113] [ticket/11566] Check that guest doesn't have reporting permission by default PHPBB3-11566 --- tests/functional/report_post_captcha.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/functional/report_post_captcha.php b/tests/functional/report_post_captcha.php index 0585be1332..af713775c5 100644 --- a/tests/functional/report_post_captcha.php +++ b/tests/functional/report_post_captcha.php @@ -21,6 +21,10 @@ class phpbb_functional_report_post_captcha_test extends phpbb_functional_test_ca public function test_guest_report_post() { + $crawler = self::request('GET', 'report.php?f=2&p=1'); + $this->add_lang('mcp'); + $this->assertContains($this->lang('USER_CANNOT_REPORT'), $crawler->filter('html')->text()); + $this->set_reporting_guest(1); $crawler = self::request('GET', 'report.php?f=2&p=1'); $this->assertContains($this->lang('CONFIRM_CODE'), $crawler->filter('html')->text()); From d4645575fdf0b787721fb8c8a240d2bd01e784f2 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 1 Jul 2013 15:23:45 +0530 Subject: [PATCH 099/113] [ticket/11566] Remove extra pair of brackets from conditional statement PHPBB3-11566 --- phpBB/report.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/report.php b/phpBB/report.php index f89a18fa8e..c92ecdfdcc 100644 --- a/phpBB/report.php +++ b/phpBB/report.php @@ -252,7 +252,7 @@ display_reasons($reason_id); $page_title = ($pm_id) ? $user->lang['REPORT_MESSAGE'] : $user->lang['REPORT_POST']; -if ((isset($captcha) && $captcha->is_solved() === false)) +if (isset($captcha) && $captcha->is_solved() === false) { $template->assign_vars(array( 'S_CONFIRM_CODE' => true, From 045e04fb6fa55ae96ba82245010a684cd2d61e5d Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 1 Jul 2013 21:52:04 +0530 Subject: [PATCH 100/113] [ticket/11566] Subsilver template error displayed after table headers PHPBB3-11561 --- phpBB/styles/subsilver2/template/report_body.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/styles/subsilver2/template/report_body.html b/phpBB/styles/subsilver2/template/report_body.html index 1653875799..57747ffac0 100644 --- a/phpBB/styles/subsilver2/template/report_body.html +++ b/phpBB/styles/subsilver2/template/report_body.html @@ -3,14 +3,14 @@
      {ERROR}
      {L_REPORT_POST}{L_REPORT_MESSAGE}
      {L_MORE_INFO}:
      {L_CAN_LEAVE_BLANK}
       
      - - - - - + + + + + From 5ed4dbb5b7aa4a0a00560eb7f3226d81ce54eca5 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 23 Jun 2013 22:40:55 +0530 Subject: [PATCH 101/113] [ticket/10838] separate database used mentioned in unit tests Separate database used for tests which is deleted each time tests are run information is added to unit tests. PHPBB3-10838 --- tests/RUNNING_TESTS.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md index bde1455855..49c59fd928 100644 --- a/tests/RUNNING_TESTS.md +++ b/tests/RUNNING_TESTS.md @@ -47,9 +47,11 @@ Database Tests By default all tests requiring a database connection will use sqlite. If you do not have sqlite installed the tests will be skipped. If you wish to run the tests on a different database you have to create a test_config.php file within -your tests directory following the same format as phpBB's config.php. An -example for mysqli can be found below. More information on configuration -options can be found on the wiki (see below). +your tests directory following the same format as phpBB's config.php. Testing +makes use of a seperate database defined in this config file and before running +the tests each time this database is deleted. An example for mysqli can be +found below. More information on configuration options can be found on the +wiki (see below). Date: Thu, 27 Jun 2013 18:38:44 +0530 Subject: [PATCH 102/113] [ticket/10838] Fix missing data PHPBB3-10838 --- tests/RUNNING_TESTS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md index 49c59fd928..d43e503e03 100644 --- a/tests/RUNNING_TESTS.md +++ b/tests/RUNNING_TESTS.md @@ -130,7 +130,7 @@ Running the tests requires your phpBB3 repository to be accessible through a local web server. As of PHP 5.4 a builtin webserver is available. If you are on PHP 5.3 you will also need to supply the URL to a webserver of your own in the 'tests/test_config.php' file. This is as simple as defining the -'$phpbb_functional_url', which contains the URL for the directory containing +'$phpbb_functional_url' variable, which contains the URL for the directory containing the board. Make sure you include the trailing slash. Note that without extensive changes to the test framework, you cannot use a board outside of the repository on which to run tests. @@ -145,7 +145,7 @@ configure the port the builtin webserver runs on using To then run the tests, you run PHPUnit, but use the phpunit.xml.functional config file instead of the default one. Specify this through the "-c" option: - phpunit -c phpunit.xml.functional + $ phpBB/vendor/bin/phpunit -c phpunit.xml.functional This will change your board's config.php file, but it makes a backup at config_dev.php, so you can restore it after the test run is complete. From 89393e11e8e10632520dc80dab638635d773e643 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 29 Jun 2013 18:42:17 +0530 Subject: [PATCH 103/113] [ticket/10838] Remove php 5.4 and builtin server references PHPBB3-10838 --- tests/RUNNING_TESTS.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md index d43e503e03..a6448c9b09 100644 --- a/tests/RUNNING_TESTS.md +++ b/tests/RUNNING_TESTS.md @@ -127,8 +127,7 @@ Running ======= Running the tests requires your phpBB3 repository to be accessible through a -local web server. As of PHP 5.4 a builtin webserver is available. If you are -on PHP 5.3 you will also need to supply the URL to a webserver of your own in +local web server. You will need to supply the URL to the webserver in the 'tests/test_config.php' file. This is as simple as defining the '$phpbb_functional_url' variable, which contains the URL for the directory containing the board. Make sure you include the trailing slash. Note that without extensive @@ -137,11 +136,6 @@ on which to run tests. $phpbb_functional_url = 'http://localhost/phpBB3/'; -On PHP 5.4 you do not need the $phpbb_functional_url parameter but you can -configure the port the builtin webserver runs on using - - $phpbb_functional_port = 8000; - To then run the tests, you run PHPUnit, but use the phpunit.xml.functional config file instead of the default one. Specify this through the "-c" option: From 440986dc3f941835febf75a30f41b69cb748a15a Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 29 Jun 2013 19:32:15 +0530 Subject: [PATCH 104/113] [ticket/10838] Fix URL for wiki and remove irrelevant line PHPBB3-10838 --- tests/RUNNING_TESTS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md index a6448c9b09..23c74f4411 100644 --- a/tests/RUNNING_TESTS.md +++ b/tests/RUNNING_TESTS.md @@ -121,7 +121,7 @@ Functional tests Functional tests test software the way a user would. They simulate a user browsing the website, but they do these steps in an automated way. -phpBB allows you to write such tests. This document will tell you how. +phpBB allows you to write such tests. Running ======= @@ -148,4 +148,4 @@ More Information ================ Further information is available on phpbb wiki: -http://wiki.phpbb.com/Unit_Tests +http://wiki.phpbb.com/Automated_Tests From fba3a9d600e9b79c8530b026fa781c99ea9ba833 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 2 Jul 2013 16:52:15 -0700 Subject: [PATCH 105/113] [ticket/11617] Missing U_ACTION in acp_captcha.php http://tracker.phpbb.com/browse/PHPBB3-11617 PHPBB3-11617 --- phpBB/includes/acp/acp_captcha.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpBB/includes/acp/acp_captcha.php b/phpBB/includes/acp/acp_captcha.php index 469a367bba..5b553d6a0d 100644 --- a/phpBB/includes/acp/acp_captcha.php +++ b/phpBB/includes/acp/acp_captcha.php @@ -124,6 +124,8 @@ class acp_captcha 'CAPTCHA_PREVIEW_TPL' => $demo_captcha->get_demo_template($id), 'S_CAPTCHA_HAS_CONFIG' => $demo_captcha->has_config(), 'CAPTCHA_SELECT' => $captcha_select, + + 'U_ACTION' => $this->u_action, )); } } From 5ef4987ffe15fe1fbafc9d9eae005f29a028dd3e Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Tue, 2 Jul 2013 18:47:56 -0700 Subject: [PATCH 106/113] [ticket/11617] Remove spaces and tabs from empty lines PHPBB3-11617 --- phpBB/includes/acp/acp_captcha.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/acp/acp_captcha.php b/phpBB/includes/acp/acp_captcha.php index 5b553d6a0d..bfec7c27d8 100644 --- a/phpBB/includes/acp/acp_captcha.php +++ b/phpBB/includes/acp/acp_captcha.php @@ -124,7 +124,7 @@ class acp_captcha 'CAPTCHA_PREVIEW_TPL' => $demo_captcha->get_demo_template($id), 'S_CAPTCHA_HAS_CONFIG' => $demo_captcha->has_config(), 'CAPTCHA_SELECT' => $captcha_select, - + 'U_ACTION' => $this->u_action, )); } From 950a3a7d952cd361c9dc3c3ff8138b0becea6f74 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 3 Jul 2013 15:31:24 +0200 Subject: [PATCH 107/113] [ticket/11619] Some tests for get_remote_file(). PHPBB3-11619 --- tests/functions/get_remote_file_test.php | 75 ++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tests/functions/get_remote_file_test.php diff --git a/tests/functions/get_remote_file_test.php b/tests/functions/get_remote_file_test.php new file mode 100644 index 0000000000..4032ca5b58 --- /dev/null +++ b/tests/functions/get_remote_file_test.php @@ -0,0 +1,75 @@ +markTestSkipped(sprintf( + 'Could not find a DNS record for hostname %s. ' . + 'Assuming network is down.', + $hostname + )); + } + + $errstr = $errno = null; + $file = get_remote_file($hostname, '/phpbb', '30x.txt', $errstr, $errno); + + $this->assertNotEquals( + 0, + strlen($file), + 'Failed asserting that the response is not empty.' + ); + + $this->assertSame( + '', + $errstr, + 'Failed asserting that the error string is empty.' + ); + + $this->assertSame( + 0, + $errno, + 'Failed asserting that the error number is 0 (i.e. no error occurred).' + ); + + $lines = explode("\n", $file); + + $this->assertGreaterThanOrEqual( + 2, + sizeof($lines), + 'Failed asserting that the version file has at least two lines.' + ); + + $this->assertStringStartsWith( + '3.', + $lines[0], + "Failed asserting that the first line of the version file starts with '3.'" + ); + + $this->assertNotSame( + false, + filter_var($lines[1], FILTER_VALIDATE_URL), + 'Failed asserting that the second line of the version file is a valid URL.' + ); + + $this->assertContains('http', $lines[1]); + $this->assertContains('phpbb.com', $lines[1], '', true); + } +} From 9e845d4641aa7f71ab713434a7a2e1edfd2876b4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 3 Jul 2013 15:31:40 +0200 Subject: [PATCH 108/113] [ticket/11619] Use HTTP/1.0 because of lack of chunked-encoding handling. PHPBB3-11619 --- phpBB/includes/functions_admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index a9d1db24a5..2f73858ea2 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -3121,7 +3121,7 @@ function get_remote_file($host, $directory, $filename, &$errstr, &$errno, $port if ($fsock = @fsockopen($host, $port, $errno, $errstr, $timeout)) { - @fputs($fsock, "GET $directory/$filename HTTP/1.1\r\n"); + @fputs($fsock, "GET $directory/$filename HTTP/1.0\r\n"); @fputs($fsock, "HOST: $host\r\n"); @fputs($fsock, "Connection: close\r\n\r\n"); From 300867ab1a688449d0a26061fa63155db1bfc101 Mon Sep 17 00:00:00 2001 From: Matthew Fonda Date: Fri, 12 Apr 2013 16:44:36 +0000 Subject: [PATCH 109/113] [ticket/11630] Improvements to the PHP lint pre-commit hook The PHP lint pre-commit hook fails to display any output when an error other than a parse error is decteced. Additionally, the hook may not display any meaningful output depending on php.ini settings. This commit removes the dependency on php.ini. PHPBB3-11630 --- git-tools/hooks/pre-commit | 57 ++++---------------------------------- 1 file changed, 5 insertions(+), 52 deletions(-) diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit index 03babe47cd..06ba15c7fa 100755 --- a/git-tools/hooks/pre-commit +++ b/git-tools/hooks/pre-commit @@ -33,9 +33,7 @@ else against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 fi -error=0 errors="" - if ! which "$PHP_BIN" >/dev/null 2>&1 then echo "PHP Syntax check failed:" @@ -73,63 +71,18 @@ do # check the staged file content for syntax errors # using php -l (lint) - # note: if display_errors=stderr in php.ini, - # parse errors are printed on stderr; otherwise - # they are printed on stdout. - # we filter everything other than parse errors - # with a grep below, therefore it should be safe - # to combine stdout and stderr in all circumstances - result=$(git cat-file -p $sha | "$PHP_BIN" -l 2>&1) + result=$(git cat-file -p $sha | "$PHP_BIN" -n -l -ddisplay_errors\=1 -derror_reporting\=E_ALL -dlog_errrors\=0 2>&1) if [ $? -ne 0 ] then - error=1 # Swap back in correct filenames - errors=$(echo "$errors"; echo "$result" |sed -e "s@in - on@in $filename on@g") + errors=$(echo "$errors"; echo "$result" | grep ':' | sed -e "s@in - on@in $filename on@g") fi done unset IFS -if [ $error -eq 1 ] +if [ -n "$errors" ] then - echo "PHP Syntax check failed:" - # php "display errors" (display_errors php.ini value) - # and "log errors" (log_errors php.ini value). - # these are independent settings - see main/main.c in php source. - # the "log errors" setting produces output which - # starts with "PHP Parse error:"; the "display errors" - # setting produces output starting with "Parse error:". - # if both are turned on php dumps the parse error twice. - # therefore here we try to grep for one version and - # if that yields no results grep for the other version. - # - # other fun php facts: - # - # 1. in cli, display_errors and log_errors have different - # destinations by default. display_errors prints to - # standard output and log_errors prints to standard error. - # whether these destinations make sense is left - # as an exercise for the reader. - # 2. as mentioned above, with all output turned on - # php will print parse errors twice, one time on stdout - # and one time on stderr. - # 3. it is possible to set both display_errors and log_errors - # to off. if this is done php will print the text - # "Errors parsing " but will not say what - # the errors are. useful behavior, this. - # 4. on my system display_errors defaults to on and - # log_errors defaults to off, therefore providing - # by default one copy of messages. your mileage may vary. - # 5. by setting display_errors=stderr and log_errors=on, - # both sets of messages will be printed on stderr. - # 6. php-cgi binary, given display_errors=stderr and - # log_errors=on, still prints both sets of messages - # on stderr, but formats one set as an html fragment. - # 7. your entry here? ;) - $echo_e "$errors" | grep "^Parse error:" - if [ $? -ne 0 ] - then - # match failed - $echo_e "$errors" | grep "^PHP Parse error:" - fi + echo "PHP Syntax check failed: " + $echo_e "$errors" exit 1 fi From 9210d735a53e3c4a4de042b49dae361c436268e1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 6 Jul 2013 19:40:25 +0200 Subject: [PATCH 110/113] [ticket/8319] Do not repeat the replacement PHPBB3-8319 --- phpBB/includes/acp/acp_bbcodes.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index ead716b300..31166a56dc 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -431,15 +431,11 @@ class acp_bbcodes $fp_replace = str_replace($token, $replace, $fp_replace); $sp_match = str_replace(preg_quote($token, '!'), $sp_tokens[$token_type], $sp_match); - if ($token_type === 'LOCAL_URL') - { - // Prepend the board url to local relative links - $sp_replace = str_replace($token, generate_board_url() . '/' . '${' . ($n + 1) . '}', $sp_replace); - } - else - { - $sp_replace = str_replace($token, '${' . ($n + 1) . '}', $sp_replace); - } + + // Prepend the board url to local relative links + $replace_prepend = ($token_type === 'LOCAL_URL') ? generate_board_url() . '/' : ''; + + $sp_replace = str_replace($token, $replace_prepend . '${' . ($n + 1) . '}', $sp_replace); } $fp_match = '!' . $fp_match . '!' . $modifiers; From 20d59c49e28511920693bb6bfb7b219e17106140 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 11 Jul 2013 12:37:03 -0400 Subject: [PATCH 111/113] [ticket/11644] Skip phpbb_dbal_order_lower_test on MySQL 5.6 PHPBB3-11644 --- tests/dbal/order_lower_test.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/dbal/order_lower_test.php b/tests/dbal/order_lower_test.php index b07f1baa91..e17295a4ea 100644 --- a/tests/dbal/order_lower_test.php +++ b/tests/dbal/order_lower_test.php @@ -18,6 +18,11 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case { $db = $this->new_dbal(); + if (strpos($db->sql_layer, 'mysql') === 0 && version_compare($db->sql_server_info(true, false), '5.6', '>=')) + { + $this->markTestSkipped('MySQL 5.6 fails to order things correctly. See also: http://tracker.phpbb.com/browse/PHPBB3-11571 http://bugs.mysql.com/bug.php?id=69005'); + } + // http://tracker.phpbb.com/browse/PHPBB3-10507 // Test ORDER BY LOWER(style_name) $db->sql_return_on_error(true); @@ -55,7 +60,7 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case 'theme_id' => 2, 'imageset_id' => 2 ) - ), + ), $db->sql_fetchrowset($result) ); } From 335d48775f66c49940429b3e4b2ab711febdf5f5 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 11 Jul 2013 12:12:47 -0400 Subject: [PATCH 112/113] [ticket/10772] Remove 3.1 code PHPBB3-10772 --- .../phpbb_functional_test_case.php | 121 ++++++++---------- 1 file changed, 51 insertions(+), 70 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 4b08a1af72..684d7a84cb 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -336,67 +336,51 @@ class phpbb_functional_test_case extends phpbb_test_case global $phpbb_root_path; $db = $this->get_db(); - if (version_compare(PHPBB_VERSION, '3.1.0-dev', '<')) + $sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'style_id' => $style_id, + 'style_name' => $style_path, + 'style_copyright' => '', + 'style_active' => 1, + 'template_id' => $style_id, + 'theme_id' => $style_id, + 'imageset_id' => $style_id, + )); + $db->sql_query($sql); + + $sql = 'INSERT INTO ' . STYLES_IMAGESET_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'imageset_id' => $style_id, + 'imageset_name' => $style_path, + 'imageset_copyright' => '', + 'imageset_path' => $style_path, + )); + $db->sql_query($sql); + + $sql = 'INSERT INTO ' . STYLES_TEMPLATE_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'template_id' => $style_id, + 'template_name' => $style_path, + 'template_copyright' => '', + 'template_path' => $style_path, + 'bbcode_bitfield' => 'kNg=', + 'template_inherits_id' => $parent_style_id, + 'template_inherit_path' => $parent_style_path, + )); + $db->sql_query($sql); + + $sql = 'INSERT INTO ' . STYLES_THEME_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'theme_id' => $style_id, + 'theme_name' => $style_path, + 'theme_copyright' => '', + 'theme_path' => $style_path, + 'theme_storedb' => 0, + 'theme_mtime' => 0, + 'theme_data' => '', + )); + $db->sql_query($sql); + + if ($style_path != 'prosilver' && $style_path != 'subsilver2') { - $sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $db->sql_build_array('INSERT', array( - 'style_id' => $style_id, - 'style_name' => $style_path, - 'style_copyright' => '', - 'style_active' => 1, - 'template_id' => $style_id, - 'theme_id' => $style_id, - 'imageset_id' => $style_id, - )); - $db->sql_query($sql); - - $sql = 'INSERT INTO ' . STYLES_IMAGESET_TABLE . ' ' . $db->sql_build_array('INSERT', array( - 'imageset_id' => $style_id, - 'imageset_name' => $style_path, - 'imageset_copyright' => '', - 'imageset_path' => $style_path, - )); - $db->sql_query($sql); - - $sql = 'INSERT INTO ' . STYLES_TEMPLATE_TABLE . ' ' . $db->sql_build_array('INSERT', array( - 'template_id' => $style_id, - 'template_name' => $style_path, - 'template_copyright' => '', - 'template_path' => $style_path, - 'bbcode_bitfield' => 'kNg=', - 'template_inherits_id' => $parent_style_id, - 'template_inherit_path' => $parent_style_path, - )); - $db->sql_query($sql); - - $sql = 'INSERT INTO ' . STYLES_THEME_TABLE . ' ' . $db->sql_build_array('INSERT', array( - 'theme_id' => $style_id, - 'theme_name' => $style_path, - 'theme_copyright' => '', - 'theme_path' => $style_path, - 'theme_storedb' => 0, - 'theme_mtime' => 0, - 'theme_data' => '', - )); - $db->sql_query($sql); - - if ($style_path != 'prosilver' && $style_path != 'subsilver2') - { - @mkdir($phpbb_root_path . 'styles/' . $style_path, 0777); - @mkdir($phpbb_root_path . 'styles/' . $style_path . '/template', 0777); - } - } - else - { - $db->sql_multi_insert(STYLES_TABLE, array( - 'style_id' => $style_id, - 'style_name' => $style_path, - 'style_copyright' => '', - 'style_active' => 1, - 'style_path' => $style_path, - 'bbcode_bitfield' => 'kNg=', - 'style_parent_id' => $parent_style_id, - 'style_parent_tree' => $parent_style_path, - )); + @mkdir($phpbb_root_path . 'styles/' . $style_path, 0777); + @mkdir($phpbb_root_path . 'styles/' . $style_path . '/template', 0777); } } @@ -412,17 +396,14 @@ class phpbb_functional_test_case extends phpbb_test_case $db = $this->get_db(); $db->sql_query('DELETE FROM ' . STYLES_TABLE . ' WHERE style_id = ' . $style_id); - if (version_compare(PHPBB_VERSION, '3.1.0-dev', '<')) - { - $db->sql_query('DELETE FROM ' . STYLES_IMAGESET_TABLE . ' WHERE imageset_id = ' . $style_id); - $db->sql_query('DELETE FROM ' . STYLES_TEMPLATE_TABLE . ' WHERE template_id = ' . $style_id); - $db->sql_query('DELETE FROM ' . STYLES_THEME_TABLE . ' WHERE theme_id = ' . $style_id); + $db->sql_query('DELETE FROM ' . STYLES_IMAGESET_TABLE . ' WHERE imageset_id = ' . $style_id); + $db->sql_query('DELETE FROM ' . STYLES_TEMPLATE_TABLE . ' WHERE template_id = ' . $style_id); + $db->sql_query('DELETE FROM ' . STYLES_THEME_TABLE . ' WHERE theme_id = ' . $style_id); - if ($style_path != 'prosilver' && $style_path != 'subsilver2') - { - @rmdir($phpbb_root_path . 'styles/' . $style_path . '/template'); - @rmdir($phpbb_root_path . 'styles/' . $style_path); - } + if ($style_path != 'prosilver' && $style_path != 'subsilver2') + { + @rmdir($phpbb_root_path . 'styles/' . $style_path . '/template'); + @rmdir($phpbb_root_path . 'styles/' . $style_path); } } From 94e5bfaadad3be2bcda5347754c3f1b5be33c620 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 11 Jul 2013 13:09:20 -0400 Subject: [PATCH 113/113] [ticket/10772] Updating tests PHPBB3-10772 --- tests/functional/forum_style_test.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/tests/functional/forum_style_test.php b/tests/functional/forum_style_test.php index 5d95538f68..59f7341eb6 100644 --- a/tests/functional/forum_style_test.php +++ b/tests/functional/forum_style_test.php @@ -14,16 +14,13 @@ class phpbb_functional_forum_style_test extends phpbb_functional_test_case { public function test_default_forum_style() { - $crawler = $this->request('GET', 'viewtopic.php?t=1&f=2'); - $this->assert_response_success(); + $crawler = self::request('GET', 'viewtopic.php?t=1&f=2'); $this->assertContains('styles/prosilver/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); - $crawler = $this->request('GET', 'viewtopic.php?t=1'); - $this->assert_response_success(); + $crawler = self::request('GET', 'viewtopic.php?t=1'); $this->assertContains('styles/prosilver/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); - $crawler = $this->request('GET', 'viewtopic.php?t=1&view=next'); - $this->assert_response_success(); + $crawler = self::request('GET', 'viewtopic.php?t=1&view=next'); $this->assertContains('styles/prosilver/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); } @@ -33,16 +30,13 @@ class phpbb_functional_forum_style_test extends phpbb_functional_test_case $this->add_style(2, 'test_style'); $db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET forum_style = 2 WHERE forum_id = 2'); - $crawler = $this->request('GET', 'viewtopic.php?t=1&f=2'); - $this->assert_response_success(); + $crawler = self::request('GET', 'viewtopic.php?t=1&f=2'); $this->assertContains('styles/test_style/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); - $crawler = $this->request('GET', 'viewtopic.php?t=1'); - $this->assert_response_success(); + $crawler = self::request('GET', 'viewtopic.php?t=1'); $this->assertContains('styles/test_style/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); - $crawler = $this->request('GET', 'viewtopic.php?t=1&view=next'); - $this->assert_response_success(); + $crawler = self::request('GET', 'viewtopic.php?t=1&view=next'); $this->assertContains('styles/test_style/', $crawler->filter('head > link[rel=stylesheet]')->attr('href')); $db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET forum_style = 0 WHERE forum_id = 2');
      {ERROR}
      {L_REPORT_POST}{L_REPORT_MESSAGE}
      {ERROR}
      {L_REPORT_POST_EXPLAIN}{L_REPORT_MESSAGE_EXPLAIN}