diff options
author | David King <imkingdavid@gmail.com> | 2012-08-19 17:24:38 -0400 |
---|---|---|
committer | David King <imkingdavid@gmail.com> | 2012-09-01 10:37:03 -0400 |
commit | 7cffebbd4997f8a41a871f8ea6fe12dc0abc08c8 (patch) | |
tree | d41e1e6027c954d1adc82f2a79c26240a4058e2f /tests/functional | |
parent | 4db4731fff5477d11757c4a4bf02aab18ab3f337 (diff) | |
download | forums-7cffebbd4997f8a41a871f8ea6fe12dc0abc08c8.tar forums-7cffebbd4997f8a41a871f8ea6fe12dc0abc08c8.tar.gz forums-7cffebbd4997f8a41a871f8ea6fe12dc0abc08c8.tar.bz2 forums-7cffebbd4997f8a41a871f8ea6fe12dc0abc08c8.tar.xz forums-7cffebbd4997f8a41a871f8ea6fe12dc0abc08c8.zip |
[task/functional] Added posting tests (reply and new topic)
PHPBB-10758
Diffstat (limited to 'tests/functional')
-rw-r--r-- | tests/functional/posting_test.php | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php new file mode 100644 index 0000000000..8d722361e0 --- /dev/null +++ b/tests/functional/posting_test.php @@ -0,0 +1,110 @@ +<?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; + + // The add_form_key()/check_form_key() safeguards present a challenge because they require + // the timestamp created in add_form_key() to be sent as-is to check_form_key() but in check_form_key() + // it won't allow the current time to be the same as the timestamp it requires. + // As such, automated scripts like this one have to somehow bypass this without being able to change + // the timestamp. The only way I can think to do so is using sleep() + sleep(1); + + // 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 two commands, see the test_post_new_topic() test + $form_data['lastclick'] = 0; + sleep(1); + + // 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()); + } +} |