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