1
0

FutureFileTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\Tests\unit\Upload;
  8. use OCA\DAV\Connector\Sabre\Directory;
  9. class FutureFileTest extends \Test\TestCase {
  10. public function testGetContentType(): void {
  11. $f = $this->mockFutureFile();
  12. $this->assertEquals('application/octet-stream', $f->getContentType());
  13. }
  14. public function testGetETag(): void {
  15. $f = $this->mockFutureFile();
  16. $this->assertEquals('1234567890', $f->getETag());
  17. }
  18. public function testGetName(): void {
  19. $f = $this->mockFutureFile();
  20. $this->assertEquals('foo.txt', $f->getName());
  21. }
  22. public function testGetLastModified(): void {
  23. $f = $this->mockFutureFile();
  24. $this->assertEquals(12121212, $f->getLastModified());
  25. }
  26. public function testGetSize(): void {
  27. $f = $this->mockFutureFile();
  28. $this->assertEquals(0, $f->getSize());
  29. }
  30. public function testGet(): void {
  31. $f = $this->mockFutureFile();
  32. $stream = $f->get();
  33. $this->assertTrue(is_resource($stream));
  34. }
  35. public function testDelete(): void {
  36. $d = $this->getMockBuilder(Directory::class)
  37. ->disableOriginalConstructor()
  38. ->setMethods(['delete'])
  39. ->getMock();
  40. $d->expects($this->once())
  41. ->method('delete');
  42. $f = new \OCA\DAV\Upload\FutureFile($d, 'foo.txt');
  43. $f->delete();
  44. }
  45. public function testPut(): void {
  46. $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
  47. $f = $this->mockFutureFile();
  48. $f->put('');
  49. }
  50. public function testSetName(): void {
  51. $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
  52. $f = $this->mockFutureFile();
  53. $f->setName('');
  54. }
  55. /**
  56. * @return \OCA\DAV\Upload\FutureFile
  57. */
  58. private function mockFutureFile() {
  59. $d = $this->getMockBuilder(Directory::class)
  60. ->disableOriginalConstructor()
  61. ->setMethods(['getETag', 'getLastModified', 'getChildren'])
  62. ->getMock();
  63. $d->expects($this->any())
  64. ->method('getETag')
  65. ->willReturn('1234567890');
  66. $d->expects($this->any())
  67. ->method('getLastModified')
  68. ->willReturn(12121212);
  69. $d->expects($this->any())
  70. ->method('getChildren')
  71. ->willReturn([]);
  72. return new \OCA\DAV\Upload\FutureFile($d, 'foo.txt');
  73. }
  74. }