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.

181 lines
5.1 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. <?php
  2. /**
  3. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. * @author Joas Schilling <nickvergessen@owncloud.com>
  5. *
  6. * @copyright Copyright (c) 2016, ownCloud, Inc.
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OCA\DAV\Tests\unit\Comments;
  23. use OCA\DAV\Comments\EntityTypeCollection as EntityTypeCollectionImplementation;
  24. use OCP\Comments\CommentsEntityEvent;
  25. use Symfony\Component\EventDispatcher\EventDispatcher;
  26. class RootCollectionTest extends \Test\TestCase {
  27. /** @var \OCP\Comments\ICommentsManager|\PHPUnit_Framework_MockObject_MockObject */
  28. protected $commentsManager;
  29. /** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject */
  30. protected $userManager;
  31. /** @var \OCP\ILogger|\PHPUnit_Framework_MockObject_MockObject */
  32. protected $logger;
  33. /** @var \OCA\DAV\Comments\RootCollection */
  34. protected $collection;
  35. /** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject */
  36. protected $userSession;
  37. /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface */
  38. protected $dispatcher;
  39. /** @var \OCP\IUser|\PHPUnit_Framework_MockObject_MockObject */
  40. protected $user;
  41. public function setUp() {
  42. parent::setUp();
  43. $this->user = $this->getMockBuilder('\OCP\IUser')
  44. ->disableOriginalConstructor()
  45. ->getMock();
  46. $this->commentsManager = $this->getMockBuilder('\OCP\Comments\ICommentsManager')
  47. ->disableOriginalConstructor()
  48. ->getMock();
  49. $this->userManager = $this->getMockBuilder('\OCP\IUserManager')
  50. ->disableOriginalConstructor()
  51. ->getMock();
  52. $this->userSession = $this->getMockBuilder('\OCP\IUserSession')
  53. ->disableOriginalConstructor()
  54. ->getMock();
  55. $this->dispatcher = new EventDispatcher();
  56. $this->logger = $this->getMockBuilder('\OCP\ILogger')
  57. ->disableOriginalConstructor()
  58. ->getMock();
  59. $this->collection = new \OCA\DAV\Comments\RootCollection(
  60. $this->commentsManager,
  61. $this->userManager,
  62. $this->userSession,
  63. $this->dispatcher,
  64. $this->logger
  65. );
  66. }
  67. protected function prepareForInitCollections() {
  68. $this->user->expects($this->any())
  69. ->method('getUID')
  70. ->will($this->returnValue('alice'));
  71. $this->userSession->expects($this->once())
  72. ->method('getUser')
  73. ->will($this->returnValue($this->user));
  74. $this->dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function(CommentsEntityEvent $event) {
  75. $event->addEntityCollection('files', function() {
  76. return true;
  77. });
  78. });
  79. }
  80. /**
  81. * @expectedException \Sabre\DAV\Exception\Forbidden
  82. */
  83. public function testCreateFile() {
  84. $this->collection->createFile('foo');
  85. }
  86. /**
  87. * @expectedException \Sabre\DAV\Exception\Forbidden
  88. */
  89. public function testCreateDirectory() {
  90. $this->collection->createDirectory('foo');
  91. }
  92. public function testGetChild() {
  93. $this->prepareForInitCollections();
  94. $etc = $this->collection->getChild('files');
  95. $this->assertTrue($etc instanceof EntityTypeCollectionImplementation);
  96. }
  97. /**
  98. * @expectedException \Sabre\DAV\Exception\NotFound
  99. */
  100. public function testGetChildInvalid() {
  101. $this->prepareForInitCollections();
  102. $this->collection->getChild('robots');
  103. }
  104. /**
  105. * @expectedException \Sabre\DAV\Exception\NotAuthenticated
  106. */
  107. public function testGetChildNoAuth() {
  108. $this->collection->getChild('files');
  109. }
  110. public function testGetChildren() {
  111. $this->prepareForInitCollections();
  112. $children = $this->collection->getChildren();
  113. $this->assertFalse(empty($children));
  114. foreach($children as $child) {
  115. $this->assertTrue($child instanceof EntityTypeCollectionImplementation);
  116. }
  117. }
  118. /**
  119. * @expectedException \Sabre\DAV\Exception\NotAuthenticated
  120. */
  121. public function testGetChildrenNoAuth() {
  122. $this->collection->getChildren();
  123. }
  124. public function testChildExistsYes() {
  125. $this->prepareForInitCollections();
  126. $this->assertTrue($this->collection->childExists('files'));
  127. }
  128. public function testChildExistsNo() {
  129. $this->prepareForInitCollections();
  130. $this->assertFalse($this->collection->childExists('robots'));
  131. }
  132. /**
  133. * @expectedException \Sabre\DAV\Exception\NotAuthenticated
  134. */
  135. public function testChildExistsNoAuth() {
  136. $this->collection->childExists('files');
  137. }
  138. /**
  139. * @expectedException \Sabre\DAV\Exception\Forbidden
  140. */
  141. public function testDelete() {
  142. $this->collection->delete();
  143. }
  144. public function testGetName() {
  145. $this->assertSame('comments', $this->collection->getName());
  146. }
  147. /**
  148. * @expectedException \Sabre\DAV\Exception\Forbidden
  149. */
  150. public function testSetName() {
  151. $this->collection->setName('foobar');
  152. }
  153. public function testGetLastModified() {
  154. $this->assertSame(null, $this->collection->getLastModified());
  155. }
  156. }