logsettingscontrollertest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. /**
  14. * @package OC\Settings\Controller
  15. */
  16. class LogSettingsControllerTest extends \Test\TestCase {
  17. /** @var \OCP\AppFramework\IAppContainer */
  18. private $container;
  19. /** @var LogSettingsController */
  20. private $logSettingsController;
  21. protected function setUp() {
  22. $app = new Application();
  23. $this->container = $app->getContainer();
  24. $this->container['Config'] = $this->getMockBuilder('\OCP\IConfig')
  25. ->disableOriginalConstructor()->getMock();
  26. $this->container['AppName'] = 'settings';
  27. $this->logSettingsController = $this->container['LogSettingsController'];
  28. }
  29. /**
  30. * @dataProvider logLevelData
  31. */
  32. public function testSetLogLevel($level, $inRange) {
  33. if ($inRange) {
  34. $this->container['Config']
  35. ->expects($this->once())
  36. ->method('setSystemValue')
  37. ->with('loglevel', $level);
  38. }
  39. $response = $this->logSettingsController->setLogLevel($level)->getData();
  40. if ($inRange) {
  41. $expectedResponse = ['level' => $level];
  42. } else {
  43. $expectedResponse = ['message' => 'log-level out of allowed range'];
  44. }
  45. $this->assertSame($expectedResponse, $response);
  46. }
  47. public function logLevelData() {
  48. return [
  49. [-1, false],
  50. [0, true],
  51. [1, true],
  52. [2, true],
  53. [3, true],
  54. [4, true],
  55. [5, false],
  56. ];
  57. }
  58. public function testDownload() {
  59. $response = $this->logSettingsController->download();
  60. $this->assertInstanceOf('\OCP\AppFramework\Http\StreamResponse', $response);
  61. }
  62. }