aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOleg Pudeyev <oleg@bsdpower.com>2012-12-16 16:48:15 -0500
committerOleg Pudeyev <oleg@bsdpower.com>2012-12-16 16:48:15 -0500
commitda2f0757d777e3b7d34ac65884400ce276d99c9a (patch)
tree094cf50a5c803bf5b79aeaf57afa80873820a773 /tests
parent0f35f94398dbb8b64d420dc8ebcdea760cade113 (diff)
parenta288c4b66bdd82de70ff14750890e9829fa7d9b9 (diff)
downloadforums-da2f0757d777e3b7d34ac65884400ce276d99c9a.tar
forums-da2f0757d777e3b7d34ac65884400ce276d99c9a.tar.gz
forums-da2f0757d777e3b7d34ac65884400ce276d99c9a.tar.bz2
forums-da2f0757d777e3b7d34ac65884400ce276d99c9a.tar.xz
forums-da2f0757d777e3b7d34ac65884400ce276d99c9a.zip
Merge PR #1140 branch 'develop-olympus' into develop
* develop-olympus: [ticket/8610] Update comment [ticket/8610] Do not use requests to submit posts except in posting_test.php [ticket/8610] Move posting helpers to separate file [ticket/8610] Create helper functions to create topic/post in functional tests [ticket/8610] Use phpbb_update_rows_avoiding_duplicates [ticket/8610] Revert some funky merging I did from rebase [ticket/8610] Add some comments [ticket/8610] Update Bookmarks and Subscriptions when splitting topics [ticket/8610] Update Bookmarks when merging posts into another topic [ticket/8610] Update Bookmarks when forking topics [ticket/8610] Update Bookmarks when merging topics
Diffstat (limited to 'tests')
-rw-r--r--tests/functional/posting_test.php149
1 files changed, 93 insertions, 56 deletions
diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php
index f54a3591b2..d05207edf0 100644
--- a/tests/functional/posting_test.php
+++ b/tests/functional/posting_test.php
@@ -15,70 +15,93 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case
public function test_post_new_topic()
{
$this->login();
- $this->add_lang('posting');
- $crawler = $this->request('GET', 'posting.php?mode=post&f=2&sid=' . $this->sid);
- $this->assertContains($this->lang('POST_TOPIC'), $crawler->filter('html')->text());
+ // Test creating topic
+ $post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.');
- $hidden_fields = array();
- $hidden_fields[] = $crawler->filter('[type="hidden"]')->each(function ($node, $i) {
- return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value'));
- });
+ $crawler = $this->request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
+ $this->assertContains('This is a test topic posted by the testing framework.', $crawler->filter('html')->text());
- $test_message = 'This is a test topic posted by the testing framework.';
- $form_data = array(
- 'subject' => 'Test Topic 1',
- 'message' => $test_message,
- 'post' => true,
- 'f' => 2,
- 'mode' => 'post',
- 'sid' => $this->sid,
- );
+ // Test creating a reply
+ $post2 = $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post posted by the testing framework.');
- foreach ($hidden_fields as $fields)
- {
- foreach($fields as $field)
- {
- $form_data[$field['name']] = $field['value'];
- }
- }
+ $crawler = $this->request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}");
+ $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text());
- // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened)
- // is not at least 2 seconds before submission, cancel the form
- $form_data['lastclick'] = 0;
+ // Test quoting a message
+ $crawler = $this->request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}");
+ $this->assert_response_success();
+ $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text());
+ }
- // I use a request because the form submission method does not allow you to send data that is not
- // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs)
- // Instead, I send it as a request with the submit button "post" set to true.
- $crawler = $this->client->request('POST', 'posting.php', $form_data);
- $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text());
+ /**
+ * Creates a topic
+ *
+ * Be sure to login before creating
+ *
+ * @param int $forum_id
+ * @param string $subject
+ * @param string $message
+ * @param array $additional_form_data Any additional form data to be sent in the request
+ * @return array post_id, topic_id
+ */
+ public function create_topic($forum_id, $subject, $message, $additional_form_data = array())
+ {
+ $posting_url = "posting.php?mode=post&f={$forum_id}&sid={$this->sid}";
+
+ $form_data = array_merge(array(
+ 'subject' => $subject,
+ 'message' => $message,
+ 'post' => true,
+ ), $additional_form_data);
- $crawler = $this->request('GET', 'viewtopic.php?t=2&sid=' . $this->sid);
- $this->assertContains($test_message, $crawler->filter('html')->text());
+ return $this->submit_post($posting_url, 'POST_TOPIC', $form_data);
}
- public function test_post_reply()
+ /**
+ * Creates a post
+ *
+ * Be sure to login before creating
+ *
+ * @param int $forum_id
+ * @param string $subject
+ * @param string $message
+ * @param array $additional_form_data Any additional form data to be sent in the request
+ * @return array post_id, topic_id
+ */
+ public function create_post($forum_id, $topic_id, $subject, $message, $additional_form_data = array())
{
- $this->login();
- $this->add_lang('posting');
+ $posting_url = "posting.php?mode=reply&f={$forum_id}&t={$topic_id}&sid={$this->sid}";
- $crawler = $this->request('GET', 'posting.php?mode=reply&t=2&f=2&sid=' . $this->sid);
- $this->assertContains($this->lang('POST_REPLY'), $crawler->filter('html')->text());
+ $form_data = array_merge(array(
+ 'subject' => $subject,
+ 'message' => $message,
+ 'post' => true,
+ ), $additional_form_data);
- $hidden_fields = array();
- $hidden_fields[] = $crawler->filter('[type="hidden"]')->each(function ($node, $i) {
- return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value'));
- });
+ return $this->submit_post($posting_url, 'POST_REPLY', $form_data);
+ }
+
+ /**
+ * Helper for submitting posts
+ *
+ * @param string $posting_url
+ * @param string $posting_contains
+ * @param array $form_data
+ * @return array post_id, topic_id
+ */
+ protected function submit_post($posting_url, $posting_contains, $form_data)
+ {
+ $this->add_lang('posting');
- $test_message = 'This is a test post posted by the testing framework.';
- $form_data = array(
- 'subject' => 'Re: Test Topic 1',
- 'message' => $test_message,
- 'post' => true,
- 't' => 2,
- 'f' => 2,
- 'mode' => 'reply',
- 'sid' => $this->sid,
+ $crawler = $this->request('GET', $posting_url);
+ $this->assert_response_success();
+ $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text());
+
+ $hidden_fields = array(
+ $crawler->filter('[type="hidden"]')->each(function ($node, $i) {
+ return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value'));
+ }),
);
foreach ($hidden_fields as $fields)
@@ -89,14 +112,28 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case
}
}
- // For reasoning behind the following command, see the test_post_new_topic() test
+ // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened)
+ // is not at least 2 seconds before submission, cancel the form
$form_data['lastclick'] = 0;
- // Submit the post
- $crawler = $this->client->request('POST', 'posting.php', $form_data);
+ // I use a request because the form submission method does not allow you to send data that is not
+ // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs)
+ // Instead, I send it as a request with the submit button "post" set to true.
+ $crawler = $this->client->request('POST', $posting_url, $form_data);
+ $this->assert_response_success();
$this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text());
- $crawler = $this->request('GET', 'viewtopic.php?t=2&sid=' . $this->sid);
- $this->assertContains($test_message, $crawler->filter('html')->text());
+ $url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri();
+
+ $matches = $topic_id = $post_id = false;
+ preg_match_all('#&t=([0-9]+)(&p=([0-9]+))?#', $url, $matches);
+
+ $topic_id = (int) (isset($matches[1][0])) ? $matches[1][0] : 0;
+ $post_id = (int) (isset($matches[3][0])) ? $matches[3][0] : 0;
+
+ return array(
+ 'topic_id' => $topic_id,
+ 'post_id' => $post_id,
+ );
}
}