Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 52 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_functional_acp_storage_settings_test | |
0.00% |
0 / 52 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| test_storage_settings | |
0.00% |
0 / 52 |
|
0.00% |
0 / 1 |
6 | |||
| 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 | /** |
| 15 | * @group functional |
| 16 | */ |
| 17 | class phpbb_functional_acp_storage_settings_test extends phpbb_functional_test_case |
| 18 | { |
| 19 | public function test_storage_settings() |
| 20 | { |
| 21 | $this->add_lang(['common', 'acp/storage']); |
| 22 | $this->login(); |
| 23 | $this->admin_login(); |
| 24 | |
| 25 | $crawler = self::request('GET', 'adm/index.php?i=acp_storage&mode=settings&sid=' . $this->sid); |
| 26 | $this->assertContainsLang('STORAGE_TITLE', $this->get_content()); |
| 27 | $this->assertContainsLang('STORAGE_TITLE_EXPLAIN', $this->get_content()); |
| 28 | |
| 29 | $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); |
| 30 | $crawler = self::submit($form); |
| 31 | $this->assertContainsLang('INFORMATION', $crawler->filter('div[class="errorbox"] > h3')->text()); |
| 32 | $this->assertContainsLang('STORAGE_NO_CHANGES', $crawler->filter('div[class="errorbox"] > p')->text()); |
| 33 | |
| 34 | // Test empty storage paths - invalid |
| 35 | $crawler = self::request('GET', 'adm/index.php?i=acp_storage&mode=settings&sid=' . $this->sid); |
| 36 | $form = $crawler->selectButton($this->lang('SUBMIT'))->form([ |
| 37 | 'attachment[path]' => '', |
| 38 | 'avatar[path]' => '', |
| 39 | 'backup[path]' => '', |
| 40 | ]); |
| 41 | $crawler = self::submit($form); |
| 42 | $this->assertContainsLang('INFORMATION', $crawler->filter('div[class="errorbox"] > h3')->text()); |
| 43 | $this->assertStringContainsString($this->lang('STORAGE_PATH_NOT_SET', $this->lang('STORAGE_ATTACHMENT_TITLE')), $crawler->filter('div[class="errorbox"] > p')->text()); |
| 44 | $this->assertStringContainsString($this->lang('STORAGE_PATH_NOT_SET', $this->lang('STORAGE_AVATAR_TITLE')), $crawler->filter('div[class="errorbox"] > p')->text()); |
| 45 | $this->assertStringContainsString($this->lang('STORAGE_PATH_NOT_SET', $this->lang('STORAGE_BACKUP_TITLE')), $crawler->filter('div[class="errorbox"] > p')->text()); |
| 46 | |
| 47 | // Test storage paths became not writable on the server afterwards |
| 48 | // Unix tests only |
| 49 | if (!defined('PHP_WINDOWS_VERSION_MAJOR')) |
| 50 | { |
| 51 | $crawler = self::request('GET', 'adm/index.php?i=acp_storage&mode=settings&sid=' . $this->sid); |
| 52 | $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); |
| 53 | $values = $form->getValues(); |
| 54 | |
| 55 | $attachments_storage_path = $values['attachment[path]']; |
| 56 | $avatar_upload_path = $values['avatar[path]']; |
| 57 | $backup_storage_path = $values['backup[path]']; |
| 58 | |
| 59 | $filesystem = new \phpbb\filesystem\filesystem; |
| 60 | |
| 61 | // Make the directory not writable |
| 62 | global $phpbb_root_path; |
| 63 | $filesystem->chmod($phpbb_root_path . $attachments_storage_path, 444); |
| 64 | $filesystem->chmod($phpbb_root_path . $avatar_upload_path, 444); |
| 65 | $filesystem->chmod($phpbb_root_path . $backup_storage_path, 444); |
| 66 | $this->assertFalse($filesystem->is_writable($phpbb_root_path . $avatar_upload_path)); |
| 67 | |
| 68 | // Visit ACP Storage settings again - warning should be displayed |
| 69 | $crawler = self::request('GET', 'adm/index.php?i=acp_storage&mode=settings&sid=' . $this->sid); |
| 70 | $this->assertContainsLang('WARNING', $crawler->filter('div[class="errorbox"] > h3')->text()); |
| 71 | $this->assertStringContainsString($this->lang('STORAGE_PATH_NOT_EXISTS', $this->lang('STORAGE_ATTACHMENT_TITLE')), $crawler->filter('div[class="errorbox"]')->text()); |
| 72 | $this->assertStringContainsString($this->lang('STORAGE_PATH_NOT_EXISTS', $this->lang('STORAGE_AVATAR_TITLE')), $crawler->filter('div[class="errorbox"]')->text()); |
| 73 | $this->assertStringContainsString($this->lang('STORAGE_PATH_NOT_EXISTS', $this->lang('STORAGE_BACKUP_TITLE')), $crawler->filter('div[class="errorbox"]')->text()); |
| 74 | |
| 75 | // Restore default state |
| 76 | $filesystem->chmod($phpbb_root_path . $attachments_storage_path, 777); |
| 77 | $filesystem->chmod($phpbb_root_path . $avatar_upload_path, 777); |
| 78 | $filesystem->chmod($phpbb_root_path . $backup_storage_path, 777); |
| 79 | $this->assertTrue($filesystem->is_writable($phpbb_root_path . $attachments_storage_path)); |
| 80 | $this->assertTrue($filesystem->is_writable($phpbb_root_path . $avatar_upload_path)); |
| 81 | $this->assertTrue($filesystem->is_writable($phpbb_root_path . $backup_storage_path)); |
| 82 | |
| 83 | $crawler = self::request('GET', 'adm/index.php?i=acp_storage&mode=settings&sid=' . $this->sid); |
| 84 | $this->assertStringNotContainsString($this->lang('STORAGE_PATH_NOT_SET', $this->lang('STORAGE_ATTACHMENT_TITLE')), $this->get_content()); |
| 85 | $this->assertStringNotContainsString($this->lang('STORAGE_PATH_NOT_SET', $this->lang('STORAGE_AVATAR_TITLE')), $this->get_content()); |
| 86 | $this->assertStringNotContainsString($this->lang('STORAGE_PATH_NOT_SET', $this->lang('STORAGE_BACKUP_TITLE')), $this->get_content()); |
| 87 | |
| 88 | $this->assertStringNotContainsString($this->lang('STORAGE_PATH_NOT_EXISTS', $this->lang('STORAGE_ATTACHMENT_TITLE')), $this->get_content()); |
| 89 | $this->assertStringNotContainsString($this->lang('STORAGE_PATH_NOT_EXISTS', $this->lang('STORAGE_AVATAR_TITLE')), $this->get_content()); |
| 90 | $this->assertStringNotContainsString($this->lang('STORAGE_PATH_NOT_EXISTS', $this->lang('STORAGE_BACKUP_TITLE')), $this->get_content()); |
| 91 | } |
| 92 | } |
| 93 | } |