AdminTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Files\Tests\Settings;
  25. use bantu\IniGetWrapper\IniGetWrapper;
  26. use OCA\Files\Settings\Admin;
  27. use OCP\AppFramework\Http\TemplateResponse;
  28. use OCP\IRequest;
  29. use OCP\Util;
  30. use Test\TestCase;
  31. class AdminTest extends TestCase {
  32. /** @var Admin */
  33. private $admin;
  34. /** @var IniGetWrapper */
  35. private $iniGetWrapper;
  36. /** @var IRequest */
  37. private $request;
  38. public function setUp() {
  39. parent::setUp();
  40. $this->iniGetWrapper = $this->getMockBuilder('\bantu\IniGetWrapper\IniGetWrapper')->disableOriginalConstructor()->getMock();
  41. $this->request = $this->getMockBuilder(IRequest::class)->getMock();
  42. $this->admin = new Admin(
  43. $this->iniGetWrapper,
  44. $this->request
  45. );
  46. }
  47. public function testGetForm() {
  48. $htaccessWorking = (getenv('htaccessWorking') == 'true');
  49. $htaccessWritable = is_writable(\OC::$SERVERROOT.'/.htaccess');
  50. $userIniWritable = is_writable(\OC::$SERVERROOT.'/.user.ini');
  51. $this->iniGetWrapper
  52. ->expects($this->at(0))
  53. ->method('getBytes')
  54. ->with('upload_max_filesize')
  55. ->willReturn(1234);
  56. $this->iniGetWrapper
  57. ->expects($this->at(1))
  58. ->method('getBytes')
  59. ->with('post_max_size')
  60. ->willReturn(1234);
  61. $params = [
  62. 'uploadChangable' => (($htaccessWorking and $htaccessWritable) or $userIniWritable ),
  63. 'uploadMaxFilesize' => '1 KB',
  64. 'displayMaxPossibleUploadSize' => PHP_INT_SIZE === 4,
  65. 'maxPossibleUploadSize' => Util::humanFileSize(PHP_INT_MAX),
  66. ];
  67. $expected = new TemplateResponse('files', 'admin', $params, '');
  68. $this->assertEquals($expected, $this->admin->getForm());
  69. }
  70. public function testGetSection() {
  71. $this->assertSame('server', $this->admin->getSection());
  72. }
  73. public function testGetPriority() {
  74. $this->assertSame(5, $this->admin->getPriority());
  75. }
  76. }