diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2016-02-25 09:08:12 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2016-05-23 09:03:48 +0200 |
commit | 54f8822670b86899fea2ad593455f5a6fc5f57ee (patch) | |
tree | eafb5a68d4752d6bb519743f5b28e91eaf714c18 /apps/dav | |
parent | c9fda848411d3369d39201a4ebcf8505fb70adce (diff) | |
download | nextcloud-server-54f8822670b86899fea2ad593455f5a6fc5f57ee.tar.gz nextcloud-server-54f8822670b86899fea2ad593455f5a6fc5f57ee.zip |
Fix unit tests
Diffstat (limited to 'apps/dav')
-rw-r--r-- | apps/dav/tests/unit/comments/entitycollection.php | 8 | ||||
-rw-r--r-- | apps/dav/tests/unit/comments/entitytypecollection.php | 35 | ||||
-rw-r--r-- | apps/dav/tests/unit/comments/rootcollection.php | 24 |
3 files changed, 37 insertions, 30 deletions
diff --git a/apps/dav/tests/unit/comments/entitycollection.php b/apps/dav/tests/unit/comments/entitycollection.php index 5bf155f12ba..bc009e92549 100644 --- a/apps/dav/tests/unit/comments/entitycollection.php +++ b/apps/dav/tests/unit/comments/entitycollection.php @@ -23,18 +23,21 @@ namespace OCA\DAV\Tests\Unit\Comments; class EntityCollection extends \Test\TestCase { + /** @var \OCP\Comments\ICommentsManager|\PHPUnit_Framework_MockObject_MockObject */ protected $commentsManager; - protected $folder; + /** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject */ protected $userManager; + /** @var \OCP\ILogger|\PHPUnit_Framework_MockObject_MockObject */ protected $logger; + /** @var \OCA\DAV\Comments\EntityCollection */ protected $collection; + /** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject */ protected $userSession; public function setUp() { parent::setUp(); $this->commentsManager = $this->getMock('\OCP\Comments\ICommentsManager'); - $this->folder = $this->getMock('\OCP\Files\Folder'); $this->userManager = $this->getMock('\OCP\IUserManager'); $this->userSession = $this->getMock('\OCP\IUserSession'); $this->logger = $this->getMock('\OCP\ILogger'); @@ -43,7 +46,6 @@ class EntityCollection extends \Test\TestCase { '19', 'files', $this->commentsManager, - $this->folder, $this->userManager, $this->userSession, $this->logger diff --git a/apps/dav/tests/unit/comments/entitytypecollection.php b/apps/dav/tests/unit/comments/entitytypecollection.php index f3aa2dbd71f..96b1cad8373 100644 --- a/apps/dav/tests/unit/comments/entitytypecollection.php +++ b/apps/dav/tests/unit/comments/entitytypecollection.php @@ -25,52 +25,52 @@ use OCA\DAV\Comments\EntityCollection as EntityCollectionImplemantation; class EntityTypeCollection extends \Test\TestCase { + /** @var \OCP\Comments\ICommentsManager|\PHPUnit_Framework_MockObject_MockObject */ protected $commentsManager; - protected $folder; + /** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject */ protected $userManager; + /** @var \OCP\ILogger|\PHPUnit_Framework_MockObject_MockObject */ protected $logger; + /** @var \OCA\DAV\Comments\EntityTypeCollection */ protected $collection; + /** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject */ protected $userSession; + protected $childMap = []; + public function setUp() { parent::setUp(); $this->commentsManager = $this->getMock('\OCP\Comments\ICommentsManager'); - $this->folder = $this->getMock('\OCP\Files\Folder'); $this->userManager = $this->getMock('\OCP\IUserManager'); $this->userSession = $this->getMock('\OCP\IUserSession'); $this->logger = $this->getMock('\OCP\ILogger'); + $instance = $this; + $this->collection = new \OCA\DAV\Comments\EntityTypeCollection( 'files', $this->commentsManager, - $this->folder, $this->userManager, $this->userSession, - $this->logger + $this->logger, + function ($child) use ($instance) { + return !empty($instance->childMap[$child]); + } ); } public function testChildExistsYes() { - $this->folder->expects($this->once()) - ->method('getById') - ->with('17') - ->will($this->returnValue([$this->getMock('\OCP\Files\Node')])); + $this->childMap[17] = true; $this->assertTrue($this->collection->childExists('17')); } public function testChildExistsNo() { - $this->folder->expects($this->once()) - ->method('getById') - ->will($this->returnValue([])); $this->assertFalse($this->collection->childExists('17')); } public function testGetChild() { - $this->folder->expects($this->once()) - ->method('getById') - ->with('17') - ->will($this->returnValue([$this->getMock('\OCP\Files\Node')])); + $this->childMap[17] = true; $ec = $this->collection->getChild('17'); $this->assertTrue($ec instanceof EntityCollectionImplemantation); @@ -80,11 +80,6 @@ class EntityTypeCollection extends \Test\TestCase { * @expectedException \Sabre\DAV\Exception\NotFound */ public function testGetChildException() { - $this->folder->expects($this->once()) - ->method('getById') - ->with('17') - ->will($this->returnValue([])); - $this->collection->getChild('17'); } diff --git a/apps/dav/tests/unit/comments/rootcollection.php b/apps/dav/tests/unit/comments/rootcollection.php index 369006e7159..a59482fba73 100644 --- a/apps/dav/tests/unit/comments/rootcollection.php +++ b/apps/dav/tests/unit/comments/rootcollection.php @@ -22,15 +22,24 @@ namespace OCA\DAV\Tests\Unit\Comments; use OCA\DAV\Comments\EntityTypeCollection as EntityTypeCollectionImplementation; +use OCP\Comments\CommentsEntityEvent; +use Symfony\Component\EventDispatcher\EventDispatcher; class RootCollection extends \Test\TestCase { + /** @var \OCP\Comments\ICommentsManager|\PHPUnit_Framework_MockObject_MockObject */ protected $commentsManager; + /** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject */ protected $userManager; + /** @var \OCP\ILogger|\PHPUnit_Framework_MockObject_MockObject */ protected $logger; + /** @var \OCA\DAV\Comments\RootCollection */ protected $collection; + /** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject */ protected $userSession; - protected $rootFolder; + /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface */ + protected $dispatcher; + /** @var \OCP\IUser|\PHPUnit_Framework_MockObject_MockObject */ protected $user; public function setUp() { @@ -41,14 +50,14 @@ class RootCollection extends \Test\TestCase { $this->commentsManager = $this->getMock('\OCP\Comments\ICommentsManager'); $this->userManager = $this->getMock('\OCP\IUserManager'); $this->userSession = $this->getMock('\OCP\IUserSession'); - $this->rootFolder = $this->getMock('\OCP\Files\IRootFolder'); + $this->dispatcher = new EventDispatcher(); $this->logger = $this->getMock('\OCP\ILogger'); $this->collection = new \OCA\DAV\Comments\RootCollection( $this->commentsManager, $this->userManager, $this->userSession, - $this->rootFolder, + $this->dispatcher, $this->logger ); } @@ -62,10 +71,11 @@ class RootCollection extends \Test\TestCase { ->method('getUser') ->will($this->returnValue($this->user)); - $this->rootFolder->expects($this->once()) - ->method('getUserFolder') - ->with('alice') - ->will($this->returnValue($this->getMock('\OCP\Files\Folder'))); + $this->dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function(CommentsEntityEvent $event) { + $event->addEntityCollection('files', function() { + return true; + }); + }); } /** |