FutureFileTest.php 2.2 KB

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