LogSettingsControllerTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 Tests\Settings\Controller;
  11. use \OC\Settings\Application;
  12. use OC\Settings\Controller\LogSettingsController;
  13. use OCP\AppFramework\Http\StreamResponse;
  14. use OCP\IConfig;
  15. use OCP\IL10N;
  16. use OCP\IRequest;
  17. /**
  18. * @package Tests\Settings\Controller
  19. */
  20. class LogSettingsControllerTest extends \Test\TestCase {
  21. /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
  22. private $config;
  23. /** @var LogSettingsController */
  24. private $logSettingsController;
  25. protected function setUp() {
  26. parent::setUp();
  27. $this->config = $this->createMock(IConfig::class);
  28. $l = $this->createMock(IL10N::class);
  29. $l->method('t')
  30. ->will($this->returnCallback(function($text, $parameters = []) {
  31. return vsprintf($text, $parameters);
  32. }));
  33. $this->logSettingsController = new LogSettingsController(
  34. 'settings',
  35. $this->createMock(IRequest::class),
  36. $this->config,
  37. $l
  38. );
  39. }
  40. /**
  41. * @dataProvider logLevelData
  42. */
  43. public function testSetLogLevel($level, $inRange) {
  44. if ($inRange) {
  45. $this->config->expects($this->once())
  46. ->method('setSystemValue')
  47. ->with('loglevel', $level);
  48. }
  49. $response = $this->logSettingsController->setLogLevel($level)->getData();
  50. if ($inRange) {
  51. $expectedResponse = ['level' => $level];
  52. } else {
  53. $expectedResponse = ['message' => 'log-level out of allowed range'];
  54. }
  55. $this->assertSame($expectedResponse, $response);
  56. }
  57. public function logLevelData() {
  58. return [
  59. [-1, false],
  60. [0, true],
  61. [1, true],
  62. [2, true],
  63. [3, true],
  64. [4, true],
  65. [5, false],
  66. ];
  67. }
  68. public function testDownload() {
  69. $response = $this->logSettingsController->download();
  70. $this->assertInstanceOf('\OCP\AppFramework\Http\StreamResponse', $response);
  71. $headers = $response->getHeaders();
  72. $this->assertEquals('application/octet-stream', $headers['Content-Type']);
  73. $this->assertEquals('attachment; filename="nextcloud.log"', $headers['Content-Disposition']);
  74. }
  75. }