1
0

FileAccessHelperTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * @author Lukas Reschke <lukas@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2015, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace Test\IntegrityCheck\Helpers;
  22. use OC\IntegrityCheck\Helpers\FileAccessHelper;
  23. use Test\TestCase;
  24. class FileAccessHelperTest extends TestCase {
  25. /** @var FileAccessHelper */
  26. private $fileAccessHelper;
  27. public function setUp() {
  28. parent::setUp();
  29. $this->fileAccessHelper = new FileAccessHelper();
  30. }
  31. public function testReadAndWrite() {
  32. $tempManager = \OC::$server->getTempManager();
  33. $filePath = $tempManager->getTemporaryFile();
  34. $data = 'SomeDataGeneratedByIntegrityCheck';
  35. $this->fileAccessHelper->file_put_contents($filePath, $data);
  36. $this->assertSame($data, $this->fileAccessHelper->file_get_contents($filePath));
  37. }
  38. /**
  39. * @expectedException \Exception
  40. * @expectedExceptionMessage Failed to write into /anabsolutelynotexistingfolder/on/the/system.txt
  41. */
  42. public function testFile_put_contentsWithException() {
  43. $this->fileAccessHelper->file_put_contents('/anabsolutelynotexistingfolder/on/the/system.txt', 'MyFiles');
  44. }
  45. public function testIs_writable() {
  46. $this->assertFalse($this->fileAccessHelper->is_writable('/anabsolutelynotexistingfolder/on/the/system.txt'));
  47. $this->assertTrue($this->fileAccessHelper->is_writable(\OC::$server->getTempManager()->getTemporaryFile('MyFile')));
  48. }
  49. /**
  50. * @expectedException \Exception
  51. * @expectedExceptionMessage Directory /anabsolutelynotexistingfolder/on/the/system does not exist.
  52. */
  53. public function testAssertDirectoryExistsWithException() {
  54. $this->fileAccessHelper->assertDirectoryExists('/anabsolutelynotexistingfolder/on/the/system');
  55. }
  56. public function testAssertDirectoryExists() {
  57. $this->fileAccessHelper->assertDirectoryExists(\OC::$server->getTempManager()->getTemporaryFolder('/testfolder/'));
  58. $this->addToAssertionCount(1);
  59. }
  60. }