Fix unit tests

This commit is contained in:
Joas Schilling 2016-02-25 09:08:12 +01:00
parent c9fda84841
commit 54f8822670
No known key found for this signature in database
GPG Key ID: 70A0B324C41C0946
3 changed files with 37 additions and 30 deletions

View File

@ -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

View File

@ -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');
}

View File

@ -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;
});
});
}
/**