FutureFileTest.php 2.8 KB

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