FileTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  6. * License as published by the Free Software Foundation; either
  7. * version 3 of the License, or any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  13. *
  14. * You should have received a copy of the GNU Affero General Public
  15. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. namespace Test\Log;
  18. use OC\Log\File;
  19. use Test\TestCase;
  20. /**
  21. * Class FileTest
  22. *
  23. * @group DB
  24. */
  25. class FileTest extends TestCase
  26. {
  27. private $restore_logfile;
  28. private $restore_logdateformat;
  29. protected function setUp() {
  30. parent::setUp();
  31. $config = \OC::$server->getConfig();
  32. $this->restore_logfile = $config->getSystemValue("logfile");
  33. $this->restore_logdateformat = $config->getSystemValue('logdateformat');
  34. $config->setSystemValue("logfile", $config->getSystemValue('datadirectory') . "/logtest");
  35. File::init();
  36. }
  37. protected function tearDown() {
  38. $config = \OC::$server->getConfig();
  39. if (isset($this->restore_logfile)) {
  40. $config->getSystemValue("logfile", $this->restore_logfile);
  41. } else {
  42. $config->deleteSystemValue("logfile");
  43. }
  44. if (isset($this->restore_logdateformat)) {
  45. $config->getSystemValue("logdateformat", $this->restore_logdateformat);
  46. } else {
  47. $config->deleteSystemValue("restore_logdateformat");
  48. }
  49. File::init();
  50. parent::tearDown();
  51. }
  52. public function testMicrosecondsLogTimestamp() {
  53. $config = \OC::$server->getConfig();
  54. # delete old logfile
  55. unlink($config->getSystemValue('logfile'));
  56. # set format & write log line
  57. $config->setSystemValue('logdateformat', 'u');
  58. File::write('test', 'message', \OCP\Util::ERROR);
  59. # read log line
  60. $handle = @fopen($config->getSystemValue('logfile'), 'r');
  61. $line = fread($handle, 1000);
  62. fclose($handle);
  63. # check timestamp has microseconds part
  64. $values = (array) json_decode($line);
  65. $microseconds = $values['time'];
  66. $this->assertNotEquals(0, $microseconds);
  67. }
  68. }