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
|
<?php
/**
*
* @package testing
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @group functional
*/
class phpbb_functional_avatar_test extends phpbb_functional_test_case
{
private $path;
private $form_content;
public function setUp()
{
parent::setUp();
$this->path = __DIR__ . '/fixtures/files/';
$this->login();
$this->admin_login();
$this->add_lang(array('acp/board', 'ucp', 'acp/groups'));
}
public function test_acp_settings()
{
$crawler = $this->request('GET', 'adm/index.php?i=acp_board&mode=avatar&sid=' . $this->sid);
// Check the default entries we should have
$this->assertContainsLang('ALLOW_GRAVATAR', $crawler->text());
$this->assertContainsLang('ALLOW_REMOTE', $crawler->text());
$this->assertContainsLang('ALLOW_AVATARS', $crawler->text());
$this->assertContainsLang('ALLOW_LOCAL', $crawler->text());
// Now start setting the needed settings
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$form['config[allow_avatar_local]']->select(1);
$form['config[allow_avatar_gravatar]']->select(1);
$form['config[allow_avatar_remote]']->select(1);
$form['config[allow_avatar_remote_upload]']->select(1);
$crawler = self::submit($form);
$this->assertContainsLang('CONFIG_UPDATED', $crawler->text());
}
public function test_gravatar_avatar()
{
// Get ACP settings
$crawler = $this->request('GET', 'adm/index.php?i=acp_board&mode=avatar&sid=' . $this->sid);
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$this->form_content = $form->getValues();
// Check if required form elements exist
$crawler = $this->request('GET', 'ucp.php?i=ucp_profile&mode=avatar&sid=' . $this->sid);
$this->assertContainsLang('AVATAR_TYPE', $crawler->text());
$this->assertContainsLang('AVATAR_DRIVER_GRAVATAR_TITLE', $crawler->filter('#avatar_driver')->text());
$this->assertContainsLang('GRAVATAR_AVATAR_EMAIL', $crawler->text());
// Submit gravatar with correct email and correct size
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$form['avatar_driver']->select('avatar_driver_gravatar');
$form['avatar_gravatar_email']->setValue('test@example.com');
$form['avatar_gravatar_width']->setValue(80);
$form['avatar_gravatar_height']->setValue(80);
$crawler = self::submit($form);
$this->assertContainsLang('PROFILE_UPDATED', $crawler->text());
// Submit gravatar with correct mail but incorrect size
$crawler = $this->request('GET', 'ucp.php?i=ucp_profile&mode=avatar&sid=' . $this->sid);
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$form['avatar_driver']->select('avatar_driver_gravatar');
$form['avatar_gravatar_email']->setValue('test@example.com');
$form['avatar_gravatar_width']->setValue(120);
$form['avatar_gravatar_height']->setValue(120);
$crawler = self::submit($form);
$this->assertContains(sprintf($this->lang['AVATAR_WRONG_SIZE'],
$this->form_content['config[avatar_min_width]'],
$this->form_content['config[avatar_min_height]'],
$this->form_content['config[avatar_max_width]'],
$this->form_content['config[avatar_max_height]'],
'120',
'120'
), $crawler->text());
// Submit gravatar with incorrect email and correct size
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$form['avatar_driver']->select('avatar_driver_gravatar');
$form['avatar_gravatar_email']->setValue('test.example.com');
$form['avatar_gravatar_width']->setValue(80);
$form['avatar_gravatar_height']->setValue(80);
$crawler = self::submit($form);
$this->assertContainsLang('EMAIL_INVALID_EMAIL', $crawler->text());
}
public function test_upload_avatar()
{
// Check if required form elements exist
$crawler = $this->request('GET', 'ucp.php?i=ucp_profile&mode=avatar&sid=' . $this->sid);
$this->assertContainsLang('AVATAR_DRIVER_UPLOAD_TITLE', $crawler->filter('#avatar_driver')->text());
$this->assertContainsLang('UPLOAD_AVATAR_FILE', $crawler->text());
$this->assertContainsLang('UPLOAD_AVATAR_URL', $crawler->text());
// Upload remote avatar with correct size and correct link
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$form['avatar_driver']->select('avatar_driver_upload');
// use default gravatar supplied by test@example.com and default size = 80px
$form['avatar_upload_url']->setValue('https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg');
$crawler = self::submit($form);
$this->assertContainsLang('PROFILE_UPDATED', $crawler->text());
// This will fail as the upload avatar currently expects a file that ends with an extension, e.g. .jpg
$crawler = $this->request('GET', 'ucp.php?i=ucp_profile&mode=avatar&sid=' . $this->sid);
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$form['avatar_driver']->select('avatar_driver_upload');
// use default gravatar supplied by test@example.com and size (s) = 80px
$form['avatar_upload_url']->setValue('https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=80');
$crawler = self::submit($form);
$this->assertContainsLang('AVATAR_URL_INVALID', $crawler->text());
// Submit gravatar with correct email and correct size
$crawler = $this->request('GET', 'ucp.php?i=ucp_profile&mode=avatar&sid=' . $this->sid);
$this->markTestIncomplete('Test fails due to bug in DomCrawler with Symfony < 2.2: https://github.com/symfony/symfony/issues/4674.');
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$form['avatar_driver']->select('avatar_driver_upload');
$form['avatar_upload_file']->setValue($this->path . 'valid.jpg');
$crawler = self::submit($form);
$this->assertContainsLang('PROFILE_UPDATED', $crawler->text());
}
public function test_remote_avatar()
{
// Get ACP settings
$crawler = $this->request('GET', 'adm/index.php?i=acp_board&mode=avatar&sid=' . $this->sid);
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$this->form_content = $form->getValues();
// Check if required form elements exist
$crawler = $this->request('GET', 'ucp.php?i=ucp_profile&mode=avatar&sid=' . $this->sid);
$this->assertContainsLang('AVATAR_DRIVER_REMOTE_TITLE', $crawler->filter('#avatar_driver')->text());
$this->assertContainsLang('LINK_REMOTE_AVATAR', $crawler->text());
$this->assertContainsLang('LINK_REMOTE_SIZE', $crawler->text());
// Set remote avatar with correct size and correct link
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$form['avatar_driver']->select('avatar_driver_remote');
// use default gravatar supplied by test@example.com and default size = 80px
$form['avatar_remote_url']->setValue('https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg');
$form['avatar_remote_width']->setValue(80);
$form['avatar_remote_height']->setValue(80);
$crawler = self::submit($form);
$this->assertContainsLang('PROFILE_UPDATED', $crawler->text());
// Set remote avatar with incorrect size
$crawler = $this->request('GET', 'ucp.php?i=ucp_profile&mode=avatar&sid=' . $this->sid);
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$form['avatar_driver']->select('avatar_driver_remote');
// use default gravatar supplied by test@example.com and size (s) = 80px
$form['avatar_remote_url']->setValue('https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg');
$form['avatar_remote_width']->setValue(120);
$form['avatar_remote_height']->setValue(120);
$crawler = self::submit($form);
$this->assertContains(sprintf($this->lang['AVATAR_WRONG_SIZE'],
$this->form_content['config[avatar_min_width]'],
$this->form_content['config[avatar_min_height]'],
$this->form_content['config[avatar_max_width]'],
$this->form_content['config[avatar_max_height]'],
'120',
'120'
), $crawler->text());
// Enter correct data in form entries but select incorrect avatar driver
$crawler = $this->request('GET', 'ucp.php?i=ucp_profile&mode=avatar&sid=' . $this->sid);
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$form['avatar_driver']->select('avatar_driver_upload');
// use default gravatar supplied by test@example.com and size (s) = 80px
$form['avatar_remote_url']->setValue('https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg');
$form['avatar_remote_width']->setValue(80);
$form['avatar_remote_height']->setValue(80);
$crawler = self::submit($form);
$this->assertContainsLang('NO_AVATAR_SELECTED', $crawler->text());
/*
* Enter incorrect link to a remote avatar_driver
* Due to the fact that this link to phpbb.com will not serve a 404 error but rather a 404 page,
* the remote avatar will think that this is a properly working avatar. This Bug also exists in
* the current phpBB 3.0.11 release.
*/
$crawler = $this->request('GET', 'ucp.php?i=ucp_profile&mode=avatar&sid=' . $this->sid);
$this->markTestIncomplete('Test currently fails because the remote avatar does not seem to check if it is an image');
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$form['avatar_driver']->select('avatar_driver_remote');
// use random incorrect link to phpBB.com
$form['avatar_remote_url']->setValue('https://www.phpbb.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg');
$form['avatar_remote_width']->setValue(80);
$form['avatar_remote_height']->setValue(80);
$crawler = self::submit($form);
$this->assertContainsLang('NO_AVATAR_SELECTED', $crawler->text());
}
public function test_group_ucp_settings()
{
// Test setting group avatar of admin group
$crawler = $this->request('GET', 'ucp.php?i=ucp_groups&mode=manage&action=edit&g=5&sid=' . $this->sid);
$this->assertContainsLang('AVATAR_TYPE', $crawler->text());
// Test if setting a gravatar avatar properly works
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$form['avatar_driver']->select('avatar_driver_gravatar');
$form['avatar_gravatar_email']->setValue('test@example.com');
$form['avatar_gravatar_width']->setValue(80);
$form['avatar_gravatar_height']->setValue(80);
$crawler = self::submit($form);
$this->assertContainsLang('GROUP_UPDATED', $crawler->text());
// Go back to previous page
$crawler = $this->request('GET', 'ucp.php?i=ucp_groups&mode=manage&action=edit&g=5&sid=' . $this->sid);
// Test uploading a remote avatar
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$form['avatar_driver']->select('avatar_driver_upload');
// use default gravatar supplied by test@example.com and default size = 80px
$form['avatar_upload_url']->setValue('https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg');
$crawler = self::submit($form);
$this->assertContainsLang('GROUP_UPDATED', $crawler->text());
// Go back to previous page
$crawler = $this->request('GET', 'ucp.php?i=ucp_groups&mode=manage&action=edit&g=5&sid=' . $this->sid);
// Submit gravatar with incorrect email and correct size
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$form['avatar_driver']->select('avatar_driver_gravatar');
$form['avatar_gravatar_email']->setValue('test.example.com');
$form['avatar_gravatar_width']->setValue(80);
$form['avatar_gravatar_height']->setValue(80);
$crawler = self::submit($form);
$this->assertContainsLang('EMAIL_INVALID_EMAIL', $crawler->text());
// Delete avatar
$crawler = $this->request('GET', 'ucp.php?i=ucp_groups&mode=manage&action=edit&g=5&sid=' . $this->sid);
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$form['avatar_delete']->tick();
$crawler = self::submit($form);
$this->assertContainsLang('GROUP_UPDATED', $crawler->text());
}
}
|