diff options
author | Marc Alexander <admin@m-a-styles.de> | 2013-07-17 23:55:20 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2013-07-17 23:55:20 +0200 |
commit | 96989e536dd5fc603f3598fa7a2a50414331d76c (patch) | |
tree | 2c6f33516cb784ba9a9f37a4588e68d1c6f559a9 /tests/functional | |
parent | bc6122b64ffb5c13c26991f78346fdc7dee6f9f0 (diff) | |
download | forums-96989e536dd5fc603f3598fa7a2a50414331d76c.tar forums-96989e536dd5fc603f3598fa7a2a50414331d76c.tar.gz forums-96989e536dd5fc603f3598fa7a2a50414331d76c.tar.bz2 forums-96989e536dd5fc603f3598fa7a2a50414331d76c.tar.xz forums-96989e536dd5fc603f3598fa7a2a50414331d76c.zip |
[ticket/11531] Use abstract class for avatar tests and unify test cases
PHPBB3-11531
Diffstat (limited to 'tests/functional')
-rw-r--r-- | tests/functional/avatar_acp_groups_test.php | 152 | ||||
-rw-r--r-- | tests/functional/avatar_acp_test.php | 139 | ||||
-rw-r--r-- | tests/functional/avatar_acp_users_test.php | 152 | ||||
-rw-r--r-- | tests/functional/avatar_test.php | 246 | ||||
-rw-r--r-- | tests/functional/avatar_ucp_groups_test.php | 151 | ||||
-rw-r--r-- | tests/functional/avatar_ucp_users_test.php | 151 | ||||
-rw-r--r-- | tests/functional/common_avatar_test.php | 80 |
7 files changed, 686 insertions, 385 deletions
diff --git a/tests/functional/avatar_acp_groups_test.php b/tests/functional/avatar_acp_groups_test.php new file mode 100644 index 0000000000..62b7409bdb --- /dev/null +++ b/tests/functional/avatar_acp_groups_test.php @@ -0,0 +1,152 @@ +<?php +/** + * + * @package testing + * @copyright (c) 2013 phpBB Group + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 + * + */ + +require_once dirname(__FILE__) . '/common_avatar_test.php'; + +/** + * @group functional + */ +class phpbb_functional_avatar_acp_groups_test extends phpbb_functional_common_avatar_test +{ + public function get_url() + { + return 'adm/index.php?i=acp_groups&mode=manage&action=edit&g=5'; + } + + public function avatar_acp_groups_data() + { + return array( + // Correct Gravatar + array( + 'GROUP_UPDATED', + 'avatar_driver_gravatar', + array( + 'avatar_gravatar_email' => 'test@example.com', + 'avatar_gravatar_width' => 80, + 'avatar_gravatar_height' => 80, + ), + ), + // Gravatar with incorrect size + array( + 'The submitted avatar is 120 wide and 120 high. Avatars must be at least 20 wide and 20 high, but no larger than 90 wide and 90 high.', + 'avatar_driver_gravatar', + array( + 'avatar_gravatar_email' => 'test@example.com', + 'avatar_gravatar_width' => 120, + 'avatar_gravatar_height' => 120, + ), + ), + // Incorrect email supplied for gravatar + array( + 'EMAIL_INVALID_EMAIL', + 'avatar_driver_gravatar', + array( + 'avatar_gravatar_email' => 'test.example.com', + 'avatar_gravatar_width' => 80, + 'avatar_gravatar_height' => 80, + ), + ), + // Upload image from remote + array( + 'GROUP_UPDATED', + 'avatar_driver_upload', + array( + 'avatar_upload_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + ), + ), + // Incorrect URL + array( + 'AVATAR_URL_INVALID', + 'avatar_driver_upload', + array( + 'avatar_upload_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=80', + ), + ), + /* + // Does not work due to DomCrawler issue + // Valid file upload + array( + 'GROUP_UPDATED', + 'avatar_driver_upload', + array( + 'avatar_upload_file' => array('upload', $this->path . 'valid.jpg'), + ), + ), + */ + // Correct remote avatar + array( + 'GROUP_UPDATED', + 'avatar_driver_remote', + array( + 'avatar_remote_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => 80, + 'avatar_remote_height' => 80, + ), + ), + // Remote avatar with incorrect size + array( + 'The submitted avatar is 120 wide and 120 high. Avatars must be at least 20 wide and 20 high, but no larger than 90 wide and 90 high.', + 'avatar_driver_remote', + array( + 'avatar_remote_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => 120, + 'avatar_remote_height' => 120, + ), + ), + // Wrong driver selected + array( + 'NO_AVATAR_SELECTED', + 'avatar_driver_upload', + array( + 'avatar_remote_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => 80, + 'avatar_remote_height' => 80, + ), + ), + // File does not exist, remote avatar currently does + // not check if file exists if size is specified + array( + 'GROUP_UPDATED', + 'avatar_driver_remote', + array( + 'avatar_remote_url' => 'https://www.phpbb.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => 80, + 'avatar_remote_height' => 80, + ), + ), + // File does not exist and remote avatar errors when + // trying to get the image size + array( + 'UNABLE_GET_IMAGE_SIZE', + 'avatar_driver_remote', + array( + 'avatar_remote_url' => 'https://www.phpbb.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => '', + 'avatar_remote_height' => '', + ), + ), + // Delete avatar image to reset group settings + array( + 'GROUP_UPDATED', + 'avatar_driver_gravatar', + array( + 'avatar_delete' => array('tick', ''), + ), + ), + ); + } + + /** + * @dataProvider avatar_acp_groups_data + */ + public function test_avatar_acp_groups($expected, $avatar_type, $data) + { + $this->assert_avatar_submit($expected, $avatar_type, $data); + } +} diff --git a/tests/functional/avatar_acp_test.php b/tests/functional/avatar_acp_test.php deleted file mode 100644 index 609ccbb477..0000000000 --- a/tests/functional/avatar_acp_test.php +++ /dev/null @@ -1,139 +0,0 @@ -<?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); - // 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_user_acp_settings() - { - $crawler = $this->request('GET', 'adm/index.php?i=users&u=2&sid=' . $this->sid); - - // Select "Avatar" in the drop-down menu - $form = $crawler->selectButton($this->lang('GO'))->form(); - $form['mode']->select('avatar'); - $crawler = self::submit($form); - $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('USER_AVATAR_UPDATED', $crawler->text()); - - // Go back to previous page - $crawler = $this->request('GET', 'adm/index.php?i=users&u=2&sid=' . $this->sid); - - // Select "Avatar" in the drop-down menu - $form = $crawler->selectButton($this->lang('GO'))->form(); - $form['mode']->select('avatar'); - $crawler = self::submit($form); - $this->assertContainsLang('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 = self::submit($form); - $this->assertContainsLang('USER_AVATAR_UPDATED', $crawler->text()); - - // Go back to previous page - $crawler = $this->request('GET', 'adm/index.php?i=users&u=2&sid=' . $this->sid); - - // Select "Avatar" in the drop-down menu - $form = $crawler->selectButton($this->lang('GO'))->form(); - $form['mode']->select('avatar'); - $crawler = self::submit($form); - $this->assertContainsLang('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 = self::submit($form); - $this->assertContainsLang('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->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', 'adm/index.php?i=acp_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', 'adm/index.php?i=acp_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()); - } -} diff --git a/tests/functional/avatar_acp_users_test.php b/tests/functional/avatar_acp_users_test.php new file mode 100644 index 0000000000..38ebcc8940 --- /dev/null +++ b/tests/functional/avatar_acp_users_test.php @@ -0,0 +1,152 @@ +<?php +/** + * + * @package testing + * @copyright (c) 2013 phpBB Group + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 + * + */ + +require_once dirname(__FILE__) . '/common_avatar_test.php'; + +/** + * @group functional + */ +class phpbb_functional_avatar_acp_users_test extends phpbb_functional_common_avatar_test +{ + public function get_url() + { + return 'adm/index.php?i=acp_users&u=2&mode=avatar'; + } + + public function avatar_acp_users_data() + { + return array( + // Correct gravatar + array( + 'USER_AVATAR_UPDATED', + 'avatar_driver_gravatar', + array( + 'avatar_gravatar_email' => 'test@example.com', + 'avatar_gravatar_width' => 80, + 'avatar_gravatar_height' => 80, + ), + ), + // Gravatar with incorrect sizes + array( + 'The submitted avatar is 120 wide and 120 high. Avatars must be at least 20 wide and 20 high, but no larger than 90 wide and 90 high.', + 'avatar_driver_gravatar', + array( + 'avatar_gravatar_email' => 'test@example.com', + 'avatar_gravatar_width' => 120, + 'avatar_gravatar_height' => 120, + ), + ), + // Gravatar with incorrect email + array( + 'EMAIL_INVALID_EMAIL', + 'avatar_driver_gravatar', + array( + 'avatar_gravatar_email' => 'test.example.com', + 'avatar_gravatar_width' => 80, + 'avatar_gravatar_height' => 80, + ), + ), + // Remote avatar with correct link + array( + 'USER_AVATAR_UPDATED', + 'avatar_driver_upload', + array( + 'avatar_upload_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + ), + ), + // Incorrect URL + array( + 'AVATAR_URL_INVALID', + 'avatar_driver_upload', + array( + 'avatar_upload_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=80', + ), + ), + /* + // Does not work due to DomCrawler issue + // Valid file upload + array( + 'PROFILE_UPDATED', + 'avatar_driver_upload', + array( + 'avatar_upload_file' => array('upload', $this->path . 'valid.jpg'), + ), + ), + */ + // Correct remote avatar + array( + 'USER_AVATAR_UPDATED', + 'avatar_driver_remote', + array( + 'avatar_remote_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => 80, + 'avatar_remote_height' => 80, + ), + ), + // Remote avatar with incorrect size + array( + 'The submitted avatar is 120 wide and 120 high. Avatars must be at least 20 wide and 20 high, but no larger than 90 wide and 90 high.', + 'avatar_driver_remote', + array( + 'avatar_remote_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => 120, + 'avatar_remote_height' => 120, + ), + ), + // Wrong driver selected + array( + 'NO_AVATAR_SELECTED', + 'avatar_driver_upload', + array( + 'avatar_remote_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => 80, + 'avatar_remote_height' => 80, + ), + ), + // File does not exist, remote avatar currently does + // not check if file exists if size is specified + array( + 'USER_AVATAR_UPDATED', + 'avatar_driver_remote', + array( + 'avatar_remote_url' => 'https://www.phpbb.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => 80, + 'avatar_remote_height' => 80, + ), + ), + // File does not exist and remote avatar errors when + // trying to get the image size + array( + 'UNABLE_GET_IMAGE_SIZE', + 'avatar_driver_remote', + array( + 'avatar_remote_url' => 'https://www.phpbb.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => '', + 'avatar_remote_height' => '', + ), + ), + // Reset avatar settings + array( + 'USER_AVATAR_UPDATED', + 'avatar_driver_gravatar', + array( + 'avatar_delete' => array('tick', ''), + ), + ), + ); + } + + /** + * @dataProvider avatar_acp_users_data + */ + public function test_avatar_acp_users($expected, $avatar_type, $data) + { + $this->assert_avatar_submit($expected, $avatar_type, $data); + } +} diff --git a/tests/functional/avatar_test.php b/tests/functional/avatar_test.php deleted file mode 100644 index c96ed46d30..0000000000 --- a/tests/functional/avatar_test.php +++ /dev/null @@ -1,246 +0,0 @@ -<?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()); - } -} diff --git a/tests/functional/avatar_ucp_groups_test.php b/tests/functional/avatar_ucp_groups_test.php new file mode 100644 index 0000000000..bd34f67491 --- /dev/null +++ b/tests/functional/avatar_ucp_groups_test.php @@ -0,0 +1,151 @@ +<?php +/** + * + * @package testing + * @copyright (c) 2013 phpBB Group + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 + * + */ + +require_once dirname(__FILE__) . '/common_avatar_test.php'; + +/** + * @group functional + */ +class phpbb_functional_avatar_ucp_groups_test extends phpbb_functional_common_avatar_test +{ + public function get_url() + { + return 'ucp.php?i=ucp_groups&mode=manage&action=edit&g=5'; + } + + public function avatar_ucp_groups_data() + { + return array( + // Gravatar with correct settings + array( + 'GROUP_UPDATED', + 'avatar_driver_gravatar', + array( + 'avatar_gravatar_email' => 'test@example.com', + 'avatar_gravatar_width' => 80, + 'avatar_gravatar_height' => 80, + ), + ), + // Gravatar with incorrect sizing + array( + 'The submitted avatar is 120 wide and 120 high. Avatars must be at least 20 wide and 20 high, but no larger than 90 wide and 90 high.', + 'avatar_driver_gravatar', + array( + 'avatar_gravatar_email' => 'test@example.com', + 'avatar_gravatar_width' => 120, + 'avatar_gravatar_height' => 120, + ), + ), + // Gravatar with incorrect email address + array( + 'EMAIL_INVALID_EMAIL', + 'avatar_driver_gravatar', + array( + 'avatar_gravatar_email' => 'test.example.com', + 'avatar_gravatar_width' => 80, + 'avatar_gravatar_height' => 80, + ), + ), + // Correct remote upload avatar + array( + 'GROUP_UPDATED', + 'avatar_driver_upload', + array( + 'avatar_upload_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + ), + ), + // Incorrect URL + array( + 'AVATAR_URL_INVALID', + 'avatar_driver_upload', + array( + 'avatar_upload_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=80', + ), + ), + /* + // Does not work due to DomCrawler issue + // Valid file upload + array( + 'GROUP_UPDATED', + 'avatar_driver_upload', + array( + 'avatar_upload_file' => array('upload', $this->path . 'valid.jpg'), + ), + ), + */ + // Correct remote avatar + array( + 'GROUP_UPDATED', + 'avatar_driver_remote', + array( + 'avatar_remote_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => 80, + 'avatar_remote_height' => 80, + ), + ), + // Remote avatar with incorrect size + array( + 'The submitted avatar is 120 wide and 120 high. Avatars must be at least 20 wide and 20 high, but no larger than 90 wide and 90 high.', + 'avatar_driver_remote', + array( + 'avatar_remote_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => 120, + 'avatar_remote_height' => 120, + ), + ), + // Wrong driver selected + array( + 'NO_AVATAR_SELECTED', + 'avatar_driver_upload', + array( + 'avatar_remote_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => 80, + 'avatar_remote_height' => 80, + ), + ), + // File does not exist, remote avatar currently does + // not check if file exists if size is specified + array( + 'GROUP_UPDATED', + 'avatar_driver_remote', + array( + 'avatar_remote_url' => 'https://www.phpbb.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => 80, + 'avatar_remote_height' => 80, + ), + ), + // File does not exist and remote avatar errors when + // trying to get the image size + array( + 'UNABLE_GET_IMAGE_SIZE', + 'avatar_driver_remote', + array( + 'avatar_remote_url' => 'https://www.phpbb.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => '', + 'avatar_remote_height' => '', + ), + ), + array( + 'GROUP_UPDATED', + 'avatar_driver_gravatar', + array( + 'avatar_delete' => array('tick', ''), + ), + ), + ); + } + + /** + * @dataProvider avatar_ucp_groups_data + */ + public function test_avatar_ucp_groups($expected, $avatar_type, $data) + { + $this->assert_avatar_submit($expected, $avatar_type, $data); + } +} diff --git a/tests/functional/avatar_ucp_users_test.php b/tests/functional/avatar_ucp_users_test.php new file mode 100644 index 0000000000..6b2c2344b3 --- /dev/null +++ b/tests/functional/avatar_ucp_users_test.php @@ -0,0 +1,151 @@ +<?php +/** + * + * @package testing + * @copyright (c) 2013 phpBB Group + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 + * + */ + +require_once dirname(__FILE__) . '/common_avatar_test.php'; + +/** + * @group functional + */ +class phpbb_functional_avatar_ucp_users_test extends phpbb_functional_common_avatar_test +{ + public function get_url() + { + return 'ucp.php?i=ucp_profile&mode=avatar'; + } + + public function avatar_ucp_groups_data() + { + return array( + // Gravatar with correct settings + array( + 'PROFILE_UPDATED', + 'avatar_driver_gravatar', + array( + 'avatar_gravatar_email' => 'test@example.com', + 'avatar_gravatar_width' => 80, + 'avatar_gravatar_height' => 80, + ), + ), + // Gravatar with incorrect sizing + array( + 'The submitted avatar is 120 wide and 120 high. Avatars must be at least 20 wide and 20 high, but no larger than 90 wide and 90 high.', + 'avatar_driver_gravatar', + array( + 'avatar_gravatar_email' => 'test@example.com', + 'avatar_gravatar_width' => 120, + 'avatar_gravatar_height' => 120, + ), + ), + // Gravatar with incorrect email address + array( + 'EMAIL_INVALID_EMAIL', + 'avatar_driver_gravatar', + array( + 'avatar_gravatar_email' => 'test.example.com', + 'avatar_gravatar_width' => 80, + 'avatar_gravatar_height' => 80, + ), + ), + // Correct remote upload avatar + array( + 'PROFILE_UPDATED', + 'avatar_driver_upload', + array( + 'avatar_upload_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + ), + ), + // Incorrect URL + array( + 'AVATAR_URL_INVALID', + 'avatar_driver_upload', + array( + 'avatar_upload_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=80', + ), + ), + /* + // Does not work due to DomCrawler issue + // Valid file upload + array( + 'PROFILE_UPDATED', + 'avatar_driver_upload', + array( + 'avatar_upload_file' => array('upload', $this->path . 'valid.jpg'), + ), + ), + */ + // Correct remote avatar + array( + 'PROFILE_UPDATED', + 'avatar_driver_remote', + array( + 'avatar_remote_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => 80, + 'avatar_remote_height' => 80, + ), + ), + // Remote avatar with incorrect size + array( + 'The submitted avatar is 120 wide and 120 high. Avatars must be at least 20 wide and 20 high, but no larger than 90 wide and 90 high.', + 'avatar_driver_remote', + array( + 'avatar_remote_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => 120, + 'avatar_remote_height' => 120, + ), + ), + // Wrong driver selected + array( + 'NO_AVATAR_SELECTED', + 'avatar_driver_upload', + array( + 'avatar_remote_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => 80, + 'avatar_remote_height' => 80, + ), + ), + // File does not exist, remote avatar currently does + // not check if file exists if size is specified + array( + 'PROFILE_UPDATED', + 'avatar_driver_remote', + array( + 'avatar_remote_url' => 'https://www.phpbb.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => 80, + 'avatar_remote_height' => 80, + ), + ), + // File does not exist and remote avatar errors when + // trying to get the image size + array( + 'UNABLE_GET_IMAGE_SIZE', + 'avatar_driver_remote', + array( + 'avatar_remote_url' => 'https://www.phpbb.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', + 'avatar_remote_width' => '', + 'avatar_remote_height' => '', + ), + ), + array( + 'PROFILE_UPDATED', + 'avatar_driver_gravatar', + array( + 'avatar_delete' => array('tick', ''), + ), + ), + ); + } + + /** + * @dataProvider avatar_ucp_groups_data + */ + public function test_avatar_ucp_groups($expected, $avatar_type, $data) + { + $this->assert_avatar_submit($expected, $avatar_type, $data); + } +} diff --git a/tests/functional/common_avatar_test.php b/tests/functional/common_avatar_test.php new file mode 100644 index 0000000000..c0f21d07c2 --- /dev/null +++ b/tests/functional/common_avatar_test.php @@ -0,0 +1,80 @@ +<?php +/** + * + * @package testing + * @copyright (c) 2013 phpBB Group + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 + * + */ + +/** + * @group functional + */ +abstract class phpbb_functional_common_avatar_test extends phpbb_functional_test_case +{ + private $path; + private $form_content; + + abstract function get_url(); + + 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')); + $this->set_acp_settings(); + } + + private function set_acp_settings() + { + $crawler = self::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 assert_avatar_submit($expected, $type, $data, $button_text = 'SUBMIT') + { + $crawler = self::request('GET', $this->get_url() . '&sid=' . $this->sid); + + // Test if setting a gravatar avatar properly works + $form = $crawler->selectButton($this->lang($button_text))->form(); + $form['avatar_driver']->select($type); + + foreach ($data as $key => $value) + { + if (is_array($value)) + { + $form[$key]->$value[0]($value[1]); + } + else + { + $form[$key]->setValue($value); + } + } + + $crawler = self::submit($form); + + try + { + $this->assertContainsLang($expected, $crawler->text()); + } + catch (Exception $e) + { + $this->assertContains($expected, $crawler->text()); + } + } +} |