rework test about overwriting default comments manager

This commit is contained in:
Arthur Schiwon 2015-12-03 21:53:58 +01:00
parent d3692c3283
commit 8acbb7aef9
3 changed files with 48 additions and 18 deletions

View File

@ -2,27 +2,12 @@
namespace Test\Comments; namespace Test\Comments;
use Test\TestCase;
/** /**
* Class Test_Comments_FakeFactory * Class FakeFactory
*/ */
class Test_Comments_FakeFactory extends TestCase implements \OCP\Comments\ICommentsManagerFactory { class FakeFactory implements \OCP\Comments\ICommentsManagerFactory {
public function getManager() { public function getManager() {
return $this->getMock('\OCP\Comments\ICommentsManager'); return new FakeManager();
}
public function testOverwriteDefaultManager() {
$config = \OC::$server->getConfig();
$defaultManagerFactory = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
$managerMock = $this->getMock('\OCP\Comments\ICommentsManager');
$config->setSystemValue('comments.managerFactory', '\Test\Comments\Test_Comments_FakeFactory');
$manager = \OC::$server->getCommentsManager();
$this->assertEquals($managerMock, $manager);
$config->setSystemValue('comments.managerFactory', $defaultManagerFactory);
} }
} }

View File

@ -0,0 +1,33 @@
<?php
namespace Test\Comments;
/**
* Class FakeManager
*/
class FakeManager implements \OCP\Comments\ICommentsManager {
public function get($id) {}
public function getTree($id, $limit = 0, $offset = 0) {}
public function getForObject(
$objectType,
$objectId,
$limit = 0,
$offset = 0,
\DateTime $notOlderThan = null
) {}
public function getNumberOfCommentsForObject($objectType, $objectId) {}
public function create($actorType, $actorId, $objectType, $objectId) {}
public function delete($id) {}
public function save(\OCP\Comments\IComment &$comment) {}
public function deleteReferencesOfActor($actorType, $actorId) {}
public function deleteCommentsAtObject($objectType, $objectId) {}
}

View File

@ -174,4 +174,16 @@ class Server extends \Test\TestCase {
$this->assertInstanceOf('\OC_EventSource', $this->server->createEventSource(), 'service returned by "createEventSource" did not return the right class'); $this->assertInstanceOf('\OC_EventSource', $this->server->createEventSource(), 'service returned by "createEventSource" did not return the right class');
$this->assertInstanceOf('\OCP\IEventSource', $this->server->createEventSource(), 'service returned by "createEventSource" did not return the right class'); $this->assertInstanceOf('\OCP\IEventSource', $this->server->createEventSource(), 'service returned by "createEventSource" did not return the right class');
} }
public function testOverwriteDefaultCommentsManager() {
$config = $this->server->getConfig();
$defaultManagerFactory = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
$config->setSystemValue('comments.managerFactory', '\Test\Comments\FakeFactory');
$manager = $this->server->getCommentsManager();
$this->assertInstanceOf('\OCP\Comments\ICommentsManager', $manager);
$config->setSystemValue('comments.managerFactory', $defaultManagerFactory);
}
} }