PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/functional/posting_test.php

http://github.com/phpbb/phpbb
PHP | 303 lines | 224 code | 45 blank | 34 comment | 1 complexity | 0fa11bd6eebac1eca995a703ff6c2fbb MD5 | raw file
Possible License(s): GPL-3.0, AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * This file is part of the phpBB Forum Software package.
  5. *
  6. * @copyright (c) phpBB Limited <https://www.phpbb.com>
  7. * @license GNU General Public License, version 2 (GPL-2.0)
  8. *
  9. * For full copyright and license information, please see
  10. * the docs/CREDITS.txt file.
  11. *
  12. */
  13. /**
  14. * @group functional
  15. */
  16. class phpbb_functional_posting_test extends phpbb_functional_test_case
  17. {
  18. public function test_post_new_topic()
  19. {
  20. $this->login();
  21. // Test creating topic
  22. $post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.');
  23. $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
  24. $this->assertContains('This is a test topic posted by the testing framework.', $crawler->filter('html')->text());
  25. // Test creating a reply with bbcode
  26. $post2 = $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test [b]post[/b] posted by the testing framework.');
  27. $crawler = self::request('GET', "viewtopic.php?p={$post2['post_id']}&sid={$this->sid}");
  28. $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text());
  29. // Test quoting a message
  30. $crawler = self::request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}");
  31. $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text());
  32. }
  33. public function test_unsupported_characters()
  34. {
  35. $this->login();
  36. $post = $this->create_topic(2, "Test Topic \xF0\x9F\xA4\x94 3\xF0\x9D\x94\xBB\xF0\x9D\x95\x9A", 'This is a test with emoji character in the topic title.');
  37. $this->create_post(2, $post['topic_id'], "Re: Test Topic 1 \xF0\x9F\xA4\x94 3\xF0\x9D\x94\xBB\xF0\x9D\x95\x9A", 'This is a test with emoji characters in the topic title.');
  38. $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
  39. $this->assertContains("\xF0\x9F\xA4\x94 3\xF0\x9D\x94\xBB\xF0\x9D\x95\x9A", $crawler->text());
  40. }
  41. public function test_supported_unicode_characters()
  42. {
  43. $this->login();
  44. $post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.');
  45. $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', "This is a test with these weird characters: \xF0\x9F\x84\x90 \xF0\x9F\x84\x91");
  46. $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
  47. $this->assertContains("\xF0\x9F\x84\x90 \xF0\x9F\x84\x91", $crawler->text());
  48. }
  49. public function test_html_entities()
  50. {
  51. $this->login();
  52. $post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.');
  53. $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', '&#128512;');
  54. $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
  55. $this->assertContains('&#128512;', $crawler->text());
  56. }
  57. public function test_quote()
  58. {
  59. $text = 'Test post </textarea>"\' &&amp;amp;';
  60. $expected = "(\\[quote=admin[^\\]]*\\]\n" . preg_quote($text) . "\n\\[/quote\\])";
  61. $this->login();
  62. $topic = $this->create_topic(2, 'Test Topic 1', 'Test topic');
  63. $post = $this->create_post(2, $topic['topic_id'], 'Re: Test Topic 1', $text);
  64. $crawler = self::request('GET', "posting.php?mode=quote&f=2&t={$post['topic_id']}&p={$post['post_id']}&sid={$this->sid}");
  65. $this->assertRegexp($expected, $crawler->filter('textarea#message')->text());
  66. }
  67. /**
  68. * @see https://tracker.phpbb.com/browse/PHPBB3-14962
  69. */
  70. public function test_edit()
  71. {
  72. $this->login();
  73. $this->create_topic(2, 'Test Topic post', 'Test topic post');
  74. $url = self::$client->getCrawler()->selectLink('Edit')->link()->getUri();
  75. $post_id = $this->get_parameter_from_link($url, 'p');
  76. $crawler = self::request('GET', "posting.php?mode=edit&f=2&p={$post_id}&sid={$this->sid}");
  77. $form = $crawler->selectButton('Submit')->form();
  78. $form->setValues(array('message' => 'Edited post'));
  79. $crawler = self::submit($form);
  80. $this->assertContains('Edited post', $crawler->filter("#post_content{$post_id} .content")->text());
  81. }
  82. /**
  83. * @testdox max_quote_depth is applied to the text populating the posting form
  84. */
  85. public function test_quote_depth_form()
  86. {
  87. $text = '0[quote]1[quote]2[/quote]1[/quote]0';
  88. $expected = array(
  89. 0 => '0[quote]1[quote]2[/quote]1[/quote]0',
  90. 1 => '00',
  91. 2 => '0[quote]11[/quote]0',
  92. 3 => '0[quote]1[quote]2[/quote]1[/quote]0',
  93. );
  94. $this->login();
  95. $topic = $this->create_topic(2, 'Test Topic 1', 'Test topic');
  96. $post = $this->create_post(2, $topic['topic_id'], 'Re: Test Topic 1', $text);
  97. $quote_url = "posting.php?mode=quote&f=2&t={$post['topic_id']}&p={$post['post_id']}&sid={$this->sid}";
  98. $this->admin_login();
  99. foreach ($expected as $quote_depth => $expected_text)
  100. {
  101. $this->set_quote_depth($quote_depth);
  102. $crawler = self::request('GET', $quote_url);
  103. $this->assertRegexp(
  104. "(\\[quote=admin[^\\]]*\\]\n?" . preg_quote($expected_text) . "\n?\\[/quote\\])",
  105. $crawler->filter('textarea#message')->text()
  106. );
  107. }
  108. }
  109. /**
  110. * @testdox max_quote_depth is applied to the submitted text
  111. */
  112. public function test_quote_depth_submit()
  113. {
  114. $text = 'depth:0[quote]depth:1[quote]depth:2[quote]depth:3[/quote][/quote][/quote]';
  115. $contains = array(
  116. 0 => array('depth:0', 'depth:1', 'depth:2', 'depth:3'),
  117. 1 => array('depth:0', 'depth:1'),
  118. 2 => array('depth:0', 'depth:1', 'depth:2'),
  119. 3 => array('depth:0', 'depth:1', 'depth:2', 'depth:3'),
  120. );
  121. $not_contains = array(
  122. 0 => array(),
  123. 1 => array('depth:2', 'depth:3'),
  124. 2 => array('depth:3'),
  125. 3 => array(),
  126. );
  127. $this->login();
  128. $this->admin_login();
  129. $topic = $this->create_topic(2, 'Test Topic 1', 'Test topic');
  130. for ($quote_depth = 0; $quote_depth <= 2; ++$quote_depth)
  131. {
  132. $this->set_quote_depth($quote_depth);
  133. $post = $this->create_post(2, $topic['topic_id'], "Re: Test Topic 1#$quote_depth", $text);
  134. $url = "viewtopic.php?p={$post['post_id']}&sid={$this->sid}";
  135. $crawler = self::request('GET', $url);
  136. $text_content = $crawler->filter('#p' . $post['post_id'])->text();
  137. foreach ($contains[$quote_depth] as $contains_text)
  138. {
  139. $this->assertContains($contains_text, $text_content);
  140. }
  141. foreach ($not_contains[$quote_depth] as $not_contains_text)
  142. {
  143. $this->assertNotContains($not_contains_text, $text_content);
  144. }
  145. }
  146. }
  147. public function test_post_poll()
  148. {
  149. $this->login();
  150. $post = $this->create_topic(
  151. 2,
  152. '[ticket/14802] Test Poll Option Spacing',
  153. 'Empty/blank lines should not be additional poll options.',
  154. array('poll_title' => 'Poll Title', 'poll_option_text' => "\n A \nB\n\nC \n D\nE\n\n \n")
  155. );
  156. $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
  157. $this->assertEquals('Poll Title', $crawler->filter('.poll-title')->text());
  158. $this->assertEquals(5, $crawler->filter('*[data-poll-option-id]')->count());
  159. }
  160. protected function set_quote_depth($depth)
  161. {
  162. $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post');
  163. $form = $crawler->selectButton('Submit')->form();
  164. $values = $form->getValues();
  165. $values['config[max_quote_depth]'] = $depth;
  166. $form->setValues($values);
  167. $crawler = self::submit($form);
  168. $this->assertEquals(1, $crawler->filter('.successbox')->count());
  169. }
  170. public function test_ticket_8420()
  171. {
  172. $text = '[b][url=http://example.org] :arrow: here[/url][/b]';
  173. $this->login();
  174. $crawler = self::request('GET', 'posting.php?mode=post&f=2');
  175. $form = $crawler->selectButton('Preview')->form(array(
  176. 'subject' => 'Test subject',
  177. 'message' => $text
  178. ));
  179. $crawler = self::submit($form);
  180. $this->assertEquals($text, $crawler->filter('#message')->text());
  181. }
  182. public function test_old_signature_in_preview()
  183. {
  184. $sql = 'UPDATE ' . USERS_TABLE . "
  185. SET user_sig = '[b:2u8sdcwb]My signature[/b:2u8sdcwb]',
  186. user_sig_bbcode_uid = '2u8sdcwb',
  187. user_sig_bbcode_bitfield = 'QA=='
  188. WHERE user_id = 2";
  189. $this->get_db()->sql_query($sql);
  190. $this->login();
  191. $crawler = self::request('GET', 'posting.php?mode=post&f=2');
  192. $form = $crawler->selectButton('Preview')->form(array(
  193. 'subject' => 'Test subject',
  194. 'message' => 'My post',
  195. ));
  196. $crawler = self::submit($form);
  197. $this->assertContains(
  198. '<strong class="text-strong">My signature</strong>',
  199. $crawler->filter('#preview .signature')->html()
  200. );
  201. }
  202. /**
  203. * @ticket PHPBB3-10628
  204. */
  205. public function test_www_links_preview()
  206. {
  207. $text = 'www.example.org';
  208. $url = 'http://' . $text;
  209. $this->add_lang('posting');
  210. $this->login();
  211. $crawler = self::request('GET', 'posting.php?mode=post&f=2');
  212. $form = $crawler->selectButton('Preview')->form(array(
  213. 'subject' => 'Test subject',
  214. 'message' => $text
  215. ));
  216. $crawler = self::submit($form);
  217. // Test that the textarea remains unchanged
  218. $this->assertEquals($text, $crawler->filter('#message')->text());
  219. // Test that the preview contains the correct link
  220. $this->assertEquals($url, $crawler->filter('#preview a')->attr('href'));
  221. }
  222. public function test_allowed_schemes_links()
  223. {
  224. $text = 'http://example.org/ tcp://localhost:22/ServiceName';
  225. $this->login();
  226. $this->admin_login();
  227. // Post with default settings
  228. $crawler = self::request('GET', 'posting.php?mode=post&f=2');
  229. $form = $crawler->selectButton('Preview')->form(array(
  230. 'subject' => 'Test subject',
  231. 'message' => $text,
  232. ));
  233. $crawler = self::submit($form);
  234. $this->assertContains(
  235. '<a href="http://example.org/" class="postlink">http://example.org/</a> tcp://localhost:22/ServiceName',
  236. $crawler->filter('#preview .content')->html()
  237. );
  238. // Update allowed schemes
  239. $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post');
  240. $form = $crawler->selectButton('Submit')->form();
  241. $values = $form->getValues();
  242. $values['config[allowed_schemes_links]'] = 'https,tcp';
  243. $form->setValues($values);
  244. $crawler = self::submit($form);
  245. $this->assertEquals(1, $crawler->filter('.successbox')->count());
  246. // Post with new settings
  247. $crawler = self::request('GET', 'posting.php?mode=post&f=2');
  248. $form = $crawler->selectButton('Preview')->form(array(
  249. 'subject' => 'Test subject',
  250. 'message' => $text,
  251. ));
  252. $crawler = self::submit($form);
  253. $this->assertContains(
  254. 'http://example.org/ <a href="tcp://localhost:22/ServiceName" class="postlink">tcp://localhost:22/ServiceName</a>',
  255. $crawler->filter('#preview .content')->html()
  256. );
  257. }
  258. }