EntityCollectionTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  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\Comments;
  25. class EntityCollectionTest extends \Test\TestCase {
  26. /** @var \OCP\Comments\ICommentsManager|\PHPUnit_Framework_MockObject_MockObject */
  27. protected $commentsManager;
  28. /** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject */
  29. protected $userManager;
  30. /** @var \OCP\ILogger|\PHPUnit_Framework_MockObject_MockObject */
  31. protected $logger;
  32. /** @var \OCA\DAV\Comments\EntityCollection */
  33. protected $collection;
  34. /** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject */
  35. protected $userSession;
  36. public function setUp() {
  37. parent::setUp();
  38. $this->commentsManager = $this->getMockBuilder('\OCP\Comments\ICommentsManager')
  39. ->disableOriginalConstructor()
  40. ->getMock();
  41. $this->userManager = $this->getMockBuilder('\OCP\IUserManager')
  42. ->disableOriginalConstructor()
  43. ->getMock();
  44. $this->userSession = $this->getMockBuilder('\OCP\IUserSession')
  45. ->disableOriginalConstructor()
  46. ->getMock();
  47. $this->logger = $this->getMockBuilder('\OCP\ILogger')
  48. ->disableOriginalConstructor()
  49. ->getMock();
  50. $this->collection = new \OCA\DAV\Comments\EntityCollection(
  51. '19',
  52. 'files',
  53. $this->commentsManager,
  54. $this->userManager,
  55. $this->userSession,
  56. $this->logger
  57. );
  58. }
  59. public function testGetId() {
  60. $this->assertSame($this->collection->getId(), '19');
  61. }
  62. public function testGetChild() {
  63. $this->commentsManager->expects($this->once())
  64. ->method('get')
  65. ->with('55')
  66. ->will($this->returnValue(
  67. $this->getMockBuilder('\OCP\Comments\IComment')
  68. ->disableOriginalConstructor()
  69. ->getMock()
  70. ));
  71. $node = $this->collection->getChild('55');
  72. $this->assertTrue($node instanceof \OCA\DAV\Comments\CommentNode);
  73. }
  74. /**
  75. * @expectedException \Sabre\DAV\Exception\NotFound
  76. */
  77. public function testGetChildException() {
  78. $this->commentsManager->expects($this->once())
  79. ->method('get')
  80. ->with('55')
  81. ->will($this->throwException(new \OCP\Comments\NotFoundException()));
  82. $this->collection->getChild('55');
  83. }
  84. public function testGetChildren() {
  85. $this->commentsManager->expects($this->once())
  86. ->method('getForObject')
  87. ->with('files', '19')
  88. ->will($this->returnValue([
  89. $this->getMockBuilder('\OCP\Comments\IComment')
  90. ->disableOriginalConstructor()
  91. ->getMock()
  92. ]));
  93. $result = $this->collection->getChildren();
  94. $this->assertSame(count($result), 1);
  95. $this->assertTrue($result[0] instanceof \OCA\DAV\Comments\CommentNode);
  96. }
  97. public function testFindChildren() {
  98. $dt = new \DateTime('2016-01-10 18:48:00');
  99. $this->commentsManager->expects($this->once())
  100. ->method('getForObject')
  101. ->with('files', '19', 5, 15, $dt)
  102. ->will($this->returnValue([
  103. $this->getMockBuilder('\OCP\Comments\IComment')
  104. ->disableOriginalConstructor()
  105. ->getMock()
  106. ]));
  107. $result = $this->collection->findChildren(5, 15, $dt);
  108. $this->assertSame(count($result), 1);
  109. $this->assertTrue($result[0] instanceof \OCA\DAV\Comments\CommentNode);
  110. }
  111. public function testChildExistsTrue() {
  112. $this->assertTrue($this->collection->childExists('44'));
  113. }
  114. public function testChildExistsFalse() {
  115. $this->commentsManager->expects($this->once())
  116. ->method('get')
  117. ->with('44')
  118. ->will($this->throwException(new \OCP\Comments\NotFoundException()));
  119. $this->assertFalse($this->collection->childExists('44'));
  120. }
  121. }