You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FutureFileTest.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCA\DAV\Tests\unit\Upload;
  27. use OCA\DAV\Connector\Sabre\Directory;
  28. class FutureFileTest extends \Test\TestCase {
  29. public function testGetContentType() {
  30. $f = $this->mockFutureFile();
  31. $this->assertEquals('application/octet-stream', $f->getContentType());
  32. }
  33. public function testGetETag() {
  34. $f = $this->mockFutureFile();
  35. $this->assertEquals('1234567890', $f->getETag());
  36. }
  37. public function testGetName() {
  38. $f = $this->mockFutureFile();
  39. $this->assertEquals('foo.txt', $f->getName());
  40. }
  41. public function testGetLastModified() {
  42. $f = $this->mockFutureFile();
  43. $this->assertEquals(12121212, $f->getLastModified());
  44. }
  45. public function testGetSize() {
  46. $f = $this->mockFutureFile();
  47. $this->assertEquals(0, $f->getSize());
  48. }
  49. public function testGet() {
  50. $f = $this->mockFutureFile();
  51. $stream = $f->get();
  52. $this->assertTrue(is_resource($stream));
  53. }
  54. public function testDelete() {
  55. $d = $this->getMockBuilder(Directory::class)
  56. ->disableOriginalConstructor()
  57. ->setMethods(['delete'])
  58. ->getMock();
  59. $d->expects($this->once())
  60. ->method('delete');
  61. $f = new \OCA\DAV\Upload\FutureFile($d, 'foo.txt');
  62. $f->delete();
  63. }
  64. public function testPut() {
  65. $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
  66. $f = $this->mockFutureFile();
  67. $f->put('');
  68. }
  69. public function testSetName() {
  70. $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
  71. $f = $this->mockFutureFile();
  72. $f->setName('');
  73. }
  74. /**
  75. * @return \OCA\DAV\Upload\FutureFile
  76. */
  77. private function mockFutureFile() {
  78. $d = $this->getMockBuilder(Directory::class)
  79. ->disableOriginalConstructor()
  80. ->setMethods(['getETag', 'getLastModified', 'getChildren'])
  81. ->getMock();
  82. $d->expects($this->any())
  83. ->method('getETag')
  84. ->willReturn('1234567890');
  85. $d->expects($this->any())
  86. ->method('getLastModified')
  87. ->willReturn(12121212);
  88. $d->expects($this->any())
  89. ->method('getChildren')
  90. ->willReturn([]);
  91. return new \OCA\DAV\Upload\FutureFile($d, 'foo.txt');
  92. }
  93. }