logsettingscontrollertest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @author Georg Ehrke
  4. * @copyright 2014 Georg Ehrke <georg@ownCloud.com>
  5. *
  6. * This file is licensed under the Affero General Public License version 3 or
  7. * later.
  8. * See the COPYING-README file.
  9. */
  10. namespace Test\Settings\Controller;
  11. use \OC\Settings\Application;
  12. use OC\Settings\Controller\LogSettingsController;
  13. use OCP\AppFramework\Http\StreamResponse;
  14. /**
  15. * @package OC\Settings\Controller
  16. */
  17. class LogSettingsControllerTest extends \Test\TestCase {
  18. /** @var \OCP\AppFramework\IAppContainer */
  19. private $container;
  20. /** @var LogSettingsController */
  21. private $logSettingsController;
  22. protected function setUp() {
  23. $app = new Application();
  24. $this->container = $app->getContainer();
  25. $this->container['Config'] = $this->getMockBuilder('\OCP\IConfig')
  26. ->disableOriginalConstructor()->getMock();
  27. $this->container['AppName'] = 'settings';
  28. $this->logSettingsController = $this->container['LogSettingsController'];
  29. }
  30. /**
  31. * @dataProvider logLevelData
  32. */
  33. public function testSetLogLevel($level, $inRange) {
  34. if ($inRange) {
  35. $this->container['Config']
  36. ->expects($this->once())
  37. ->method('setSystemValue')
  38. ->with('loglevel', $level);
  39. }
  40. $response = $this->logSettingsController->setLogLevel($level)->getData();
  41. if ($inRange) {
  42. $expectedResponse = ['level' => $level];
  43. } else {
  44. $expectedResponse = ['message' => 'log-level out of allowed range'];
  45. }
  46. $this->assertSame($expectedResponse, $response);
  47. }
  48. public function logLevelData() {
  49. return [
  50. [-1, false],
  51. [0, true],
  52. [1, true],
  53. [2, true],
  54. [3, true],
  55. [4, true],
  56. [5, false],
  57. ];
  58. }
  59. public function testDownload() {
  60. $response = $this->logSettingsController->download();
  61. $expected = new StreamResponse(\OC_Log_Owncloud::getLogFilePath());
  62. $expected->addHeader('Content-Type', 'application/octet-stream');
  63. $expected->addHeader('Content-Disposition', 'attachment; filename="nextcloud.log"');
  64. $this->assertEquals($expected, $response);
  65. }
  66. }