aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2012-09-01 17:06:41 +0200
committerNils Adermann <naderman@naderman.de>2012-09-01 17:06:41 +0200
commit3bd19077dcd7f842e3b5fc50fcdcd7fa9299ad6b (patch)
tree2f8cba60d7ebe92c39eea14e558e1aecc02a2ef1
parent0ba2bfffe2df64e1f67ec23061365cdac2238a34 (diff)
parent4dd1bbc5879ae5fcae04341a9152e0366ed68bdd (diff)
downloadforums-3bd19077dcd7f842e3b5fc50fcdcd7fa9299ad6b.tar
forums-3bd19077dcd7f842e3b5fc50fcdcd7fa9299ad6b.tar.gz
forums-3bd19077dcd7f842e3b5fc50fcdcd7fa9299ad6b.tar.bz2
forums-3bd19077dcd7f842e3b5fc50fcdcd7fa9299ad6b.tar.xz
forums-3bd19077dcd7f842e3b5fc50fcdcd7fa9299ad6b.zip
Merge remote-tracking branch 'github-imkingdavid/task/functional' into develop-olympus
* github-imkingdavid/task/functional: [task/functional] Fixed DEBUG_TEST related issues [task/functional] Allow tests to bypass certain restrictions with DEBUG_TEST [task/functional] Added posting tests (reply and new topic)
-rw-r--r--phpBB/includes/functions.php2
-rw-r--r--phpBB/includes/functions_install.php9
-rw-r--r--tests/functional/posting_test.php102
-rw-r--r--tests/test_framework/phpbb_functional_test_case.php2
4 files changed, 112 insertions, 3 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 5914831539..8e7e84bf83 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -2811,7 +2811,7 @@ function check_form_key($form_name, $timespan = false, $return_page = '', $trigg
$diff = time() - $creation_time;
// If creation_time and the time() now is zero we can assume it was not a human doing this (the check for if ($diff)...
- if ($diff && ($diff <= $timespan || $timespan === -1))
+ if (defined('DEBUG_TEST') || $diff && ($diff <= $timespan || $timespan === -1))
{
$token_sid = ($user->data['user_id'] == ANONYMOUS && !empty($config['form_token_sid_guests'])) ? $user->session_id : '';
$key = sha1($creation_time . $user->data['user_form_salt'] . $form_name . $token_sid);
diff --git a/phpBB/includes/functions_install.php b/phpBB/includes/functions_install.php
index 89dfb7cd2f..eae136808c 100644
--- a/phpBB/includes/functions_install.php
+++ b/phpBB/includes/functions_install.php
@@ -551,10 +551,12 @@ function adjust_language_keys_callback($matches)
* @param string $dbms The name of the DBAL class to use
* @param array $load_extensions Array of additional extensions that should be loaded
* @param bool $debug If the debug constants should be enabled by default or not
+* @param bool $debug_test If the DEBUG_TEST constant should be added
+* NOTE: Only for use within the testing framework
*
* @return string The output to write to the file
*/
-function phpbb_create_config_file_data($data, $dbms, $load_extensions, $debug = false)
+function phpbb_create_config_file_data($data, $dbms, $load_extensions, $debug = false, $debug_test = false)
{
$load_extensions = implode(',', $load_extensions);
@@ -591,6 +593,11 @@ function phpbb_create_config_file_data($data, $dbms, $load_extensions, $debug =
$config_data .= "// @define('DEBUG_EXTRA', true);\n";
}
+ if ($debug_test)
+ {
+ $config_data .= "@define('DEBUG_TEST', true);\n";
+ }
+
return $config_data;
}
diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php
new file mode 100644
index 0000000000..f54a3591b2
--- /dev/null
+++ b/tests/functional/posting_test.php
@@ -0,0 +1,102 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @group functional
+*/
+class phpbb_functional_posting_test extends phpbb_functional_test_case
+{
+ public function test_post_new_topic()
+ {
+ $this->login();
+ $this->add_lang('posting');
+
+ $crawler = $this->request('GET', 'posting.php?mode=post&f=2&sid=' . $this->sid);
+ $this->assertContains($this->lang('POST_TOPIC'), $crawler->filter('html')->text());
+
+ $hidden_fields = array();
+ $hidden_fields[] = $crawler->filter('[type="hidden"]')->each(function ($node, $i) {
+ return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value'));
+ });
+
+ $test_message = 'This is a test topic posted by the testing framework.';
+ $form_data = array(
+ 'subject' => 'Test Topic 1',
+ 'message' => $test_message,
+ 'post' => true,
+ 'f' => 2,
+ 'mode' => 'post',
+ 'sid' => $this->sid,
+ );
+
+ foreach ($hidden_fields as $fields)
+ {
+ foreach($fields as $field)
+ {
+ $form_data[$field['name']] = $field['value'];
+ }
+ }
+
+ // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened)
+ // is not at least 2 seconds before submission, cancel the form
+ $form_data['lastclick'] = 0;
+
+ // I use a request because the form submission method does not allow you to send data that is not
+ // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs)
+ // Instead, I send it as a request with the submit button "post" set to true.
+ $crawler = $this->client->request('POST', 'posting.php', $form_data);
+ $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text());
+
+ $crawler = $this->request('GET', 'viewtopic.php?t=2&sid=' . $this->sid);
+ $this->assertContains($test_message, $crawler->filter('html')->text());
+ }
+
+ public function test_post_reply()
+ {
+ $this->login();
+ $this->add_lang('posting');
+
+ $crawler = $this->request('GET', 'posting.php?mode=reply&t=2&f=2&sid=' . $this->sid);
+ $this->assertContains($this->lang('POST_REPLY'), $crawler->filter('html')->text());
+
+ $hidden_fields = array();
+ $hidden_fields[] = $crawler->filter('[type="hidden"]')->each(function ($node, $i) {
+ return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value'));
+ });
+
+ $test_message = 'This is a test post posted by the testing framework.';
+ $form_data = array(
+ 'subject' => 'Re: Test Topic 1',
+ 'message' => $test_message,
+ 'post' => true,
+ 't' => 2,
+ 'f' => 2,
+ 'mode' => 'reply',
+ 'sid' => $this->sid,
+ );
+
+ foreach ($hidden_fields as $fields)
+ {
+ foreach($fields as $field)
+ {
+ $form_data[$field['name']] = $field['value'];
+ }
+ }
+
+ // For reasoning behind the following command, see the test_post_new_topic() test
+ $form_data['lastclick'] = 0;
+
+ // Submit the post
+ $crawler = $this->client->request('POST', 'posting.php', $form_data);
+ $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text());
+
+ $crawler = $this->request('GET', 'viewtopic.php?t=2&sid=' . $this->sid);
+ $this->assertContains($test_message, $crawler->filter('html')->text());
+ }
+}
diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php
index 2423299b7c..d35913e415 100644
--- a/tests/test_framework/phpbb_functional_test_case.php
+++ b/tests/test_framework/phpbb_functional_test_case.php
@@ -140,7 +140,7 @@ class phpbb_functional_test_case extends phpbb_test_case
$this->do_request('create_table', $data);
$this->do_request('config_file', $data);
- file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true));
+ file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true, true));
$this->do_request('final', $data);
copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx");