SimpleFileTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * @copyright 2016 Roeland Jago Douma <roeland@famdouma.nl>
  4. *
  5. * @author Roeland Jago Douma <roeland@famdouma.nl>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace Test\File\SimpleFS;
  24. use OC\Files\SimpleFS\SimpleFile;
  25. use OCP\Files\File;
  26. class SimpleFileTest extends \Test\TestCase {
  27. /** @var File|\PHPUnit_Framework_MockObject_MockObject */
  28. private $file;
  29. /** @var SimpleFile */
  30. private $simpleFile;
  31. public function setUp() {
  32. parent::setUp();
  33. $this->file = $this->createMock(File::class);
  34. $this->simpleFile = new SimpleFile($this->file);
  35. }
  36. public function testGetName() {
  37. $this->file->expects($this->once())
  38. ->method('getName')
  39. ->willReturn('myname');
  40. $this->assertEquals('myname', $this->simpleFile->getName());
  41. }
  42. public function testGetSize() {
  43. $this->file->expects($this->once())
  44. ->method('getSize')
  45. ->willReturn(42);
  46. $this->assertEquals(42, $this->simpleFile->getSize());
  47. }
  48. public function testGetETag() {
  49. $this->file->expects($this->once())
  50. ->method('getETag')
  51. ->willReturn('etag');
  52. $this->assertEquals('etag', $this->simpleFile->getETag());
  53. }
  54. public function testGetMTime() {
  55. $this->file->expects($this->once())
  56. ->method('getMTime')
  57. ->willReturn(101);
  58. $this->assertEquals(101, $this->simpleFile->getMTime());
  59. }
  60. public function testGetContent() {
  61. $this->file->expects($this->once())
  62. ->method('getContent')
  63. ->willReturn('foo');
  64. $this->assertEquals('foo', $this->simpleFile->getContent());
  65. }
  66. public function testPutContent() {
  67. $this->file->expects($this->once())
  68. ->method('putContent')
  69. ->with($this->equalTo('bar'));
  70. $this->simpleFile->putContent('bar');
  71. }
  72. public function testDelete() {
  73. $this->file->expects($this->once())
  74. ->method('delete');
  75. $this->simpleFile->delete();
  76. }
  77. public function testGetMimeType() {
  78. $this->file->expects($this->once())
  79. ->method('getMimeType')
  80. ->willReturn('app/awesome');
  81. $this->assertEquals('app/awesome', $this->simpleFile->getMimeType());
  82. }
  83. }