aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functional/avatar_acp_test.php
blob: b359212be20fec75cf2683e546537facdecba0b6 (plain)
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
<?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_acp_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/users', 'acp/groups'));
	}

	public function test_acp_settings()
	{
		$crawler = $this->request('GET', 'adm/index.php?i=acp_board&mode=avatar&sid=' . $this->sid);
		$this->assert_response_success();
		// Check the default entries we should have
		$this->assertContains($this->lang('ALLOW_GRAVATAR'), $crawler->text());
		$this->assertContains($this->lang('ALLOW_REMOTE'), $crawler->text());
		$this->assertContains($this->lang('ALLOW_AVATARS'), $crawler->text());
		$this->assertContains($this->lang('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 = $this->client->submit($form);
		$this->assertContains($this->lang('CONFIG_UPDATED'), $crawler->text());
	}

	public function test_user_acp_settings()
	{
		$crawler = $this->request('GET', 'adm/index.php?i=users&u=2&sid=' . $this->sid);
		$this->assert_response_success();

		// Select "Avatar" in the drop-down menu
		$form = $crawler->selectButton($this->lang('GO'))->form();
		$form['mode']->select('avatar');
		$crawler = $this->client->submit($form);
		$this->assertContains($this->lang('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 = $this->client->submit($form);
		$this->assertContains($this->lang('USER_AVATAR_UPDATED'), $crawler->text());

		// Go back to previous page
		$crawler = $this->request('GET', 'adm/index.php?i=users&u=2&sid=' . $this->sid);
		$this->assert_response_success();

		// Select "Avatar" in the drop-down menu
		$form = $crawler->selectButton($this->lang('GO'))->form();
		$form['mode']->select('avatar');
		$crawler = $this->client->submit($form);
		$this->assertContains($this->lang('AVATAR_TYPE'), $crawler->text());

		// 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 = $this->client->submit($form);
		$this->assertContains($this->lang('USER_AVATAR_UPDATED'), $crawler->text());

		// Go back to previous page
		$crawler = $this->request('GET', 'adm/index.php?i=users&u=2&sid=' . $this->sid);
		$this->assert_response_success();

		// Select "Avatar" in the drop-down menu
		$form = $crawler->selectButton($this->lang('GO'))->form();
		$form['mode']->select('avatar');
		$crawler = $this->client->submit($form);
		$this->assertContains($this->lang('AVATAR_TYPE'), $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 = $this->client->submit($form);
		$this->assertContains($this->lang('EMAIL_INVALID_EMAIL'), $crawler->text());
	}

	public function test_group_acp_settings()
	{
		// Test setting group avatar of admin group
		$crawler = $this->request('GET', 'adm/index.php?i=acp_groups&mode=manage&action=edit&g=5&sid=' . $this->sid);
		$this->assert_response_success();
		$this->assertContains($this->lang('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 = $this->client->submit($form);
		$this->assertContains($this->lang('GROUP_UPDATED'), $crawler->text());

		// Go back to previous page
		$crawler = $this->request('GET', 'adm/index.php?i=acp_groups&mode=manage&action=edit&g=5&sid=' . $this->sid);
		$this->assert_response_success();

		// 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 = $this->client->submit($form);
		$this->assertContains($this->lang('GROUP_UPDATED'), $crawler->text());

		// Go back to previous page
		$crawler = $this->request('GET', 'adm/index.php?i=acp_groups&mode=manage&action=edit&g=5&sid=' . $this->sid);
		$this->assert_response_success();

		// Submit gravatar with incorrect email and correct size
		$this->markTestIncomplete('No error when submitting incorrect acp group settings. This needs to be fixed ASAP.');
		$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 = $this->client->submit($form);
		$this->assertContains($this->lang('EMAIL_INVALID_EMAIL'), $crawler->text());
	}
}