|
|
|
|
@ -25,6 +25,7 @@ namespace Test\Calendar\Resource; |
|
|
|
|
|
|
|
|
|
use \OC\Calendar\Resource\Manager; |
|
|
|
|
use \OCP\Calendar\Resource\IBackend; |
|
|
|
|
use OCP\IServerContainer; |
|
|
|
|
use \Test\TestCase; |
|
|
|
|
|
|
|
|
|
class ManagerTest extends TestCase { |
|
|
|
|
@ -32,24 +33,30 @@ class ManagerTest extends TestCase { |
|
|
|
|
/** @var Manager */ |
|
|
|
|
private $manager; |
|
|
|
|
|
|
|
|
|
/** @var IServerContainer */ |
|
|
|
|
private $server; |
|
|
|
|
|
|
|
|
|
protected function setUp() { |
|
|
|
|
parent::setUp(); |
|
|
|
|
|
|
|
|
|
$this->manager = new Manager(); |
|
|
|
|
$this->server = $this->createMock(IServerContainer::class); |
|
|
|
|
$this->manager = new Manager($this->server); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testRegisterUnregisterBackend() { |
|
|
|
|
$backend1 = $this->createMock(IBackend::class); |
|
|
|
|
$backend1->method('getBackendIdentifier')->will($this->returnValue('backend_1')); |
|
|
|
|
\OC::$server->registerService('calendar_resource_backend1', function () use ($backend1) { |
|
|
|
|
return $backend1; |
|
|
|
|
}); |
|
|
|
|
$this->server->expects($this->at(0)) |
|
|
|
|
->method('query') |
|
|
|
|
->with('calendar_resource_backend1') |
|
|
|
|
->will($this->returnValue($backend1)); |
|
|
|
|
|
|
|
|
|
$backend2 = $this->createMock(IBackend::class); |
|
|
|
|
$backend2->method('getBackendIdentifier')->will($this->returnValue('backend_2')); |
|
|
|
|
\OC::$server->registerService('calendar_resource_backend2', function () use ($backend2) { |
|
|
|
|
return $backend2; |
|
|
|
|
}); |
|
|
|
|
$this->server->expects($this->at(1)) |
|
|
|
|
->method('query') |
|
|
|
|
->with('calendar_resource_backend2') |
|
|
|
|
->will($this->returnValue($backend2)); |
|
|
|
|
|
|
|
|
|
$this->manager->registerBackend('calendar_resource_backend1'); |
|
|
|
|
$this->manager->registerBackend('calendar_resource_backend2'); |
|
|
|
|
@ -68,15 +75,17 @@ class ManagerTest extends TestCase { |
|
|
|
|
public function testGetBackend() { |
|
|
|
|
$backend1 = $this->createMock(IBackend::class); |
|
|
|
|
$backend1->method('getBackendIdentifier')->will($this->returnValue('backend_1')); |
|
|
|
|
\OC::$server->registerService('calendar_resource_backend1', function () use ($backend1) { |
|
|
|
|
return $backend1; |
|
|
|
|
}); |
|
|
|
|
$this->server->expects($this->at(0)) |
|
|
|
|
->method('query') |
|
|
|
|
->with('calendar_resource_backend1') |
|
|
|
|
->will($this->returnValue($backend1)); |
|
|
|
|
|
|
|
|
|
$backend2 = $this->createMock(IBackend::class); |
|
|
|
|
$backend2->method('getBackendIdentifier')->will($this->returnValue('backend_2')); |
|
|
|
|
\OC::$server->registerService('calendar_resource_backend2', function () use ($backend2) { |
|
|
|
|
return $backend2; |
|
|
|
|
}); |
|
|
|
|
$this->server->expects($this->at(1)) |
|
|
|
|
->method('query') |
|
|
|
|
->with('calendar_resource_backend2') |
|
|
|
|
->will($this->returnValue($backend2)); |
|
|
|
|
|
|
|
|
|
$this->manager->registerBackend('calendar_resource_backend1'); |
|
|
|
|
$this->manager->registerBackend('calendar_resource_backend2'); |
|
|
|
|
@ -88,15 +97,17 @@ class ManagerTest extends TestCase { |
|
|
|
|
public function testClear() { |
|
|
|
|
$backend1 = $this->createMock(IBackend::class); |
|
|
|
|
$backend1->method('getBackendIdentifier')->will($this->returnValue('backend_1')); |
|
|
|
|
\OC::$server->registerService('calendar_resource_backend1', function () use ($backend1) { |
|
|
|
|
return $backend1; |
|
|
|
|
}); |
|
|
|
|
$this->server->expects($this->at(0)) |
|
|
|
|
->method('query') |
|
|
|
|
->with('calendar_resource_backend1') |
|
|
|
|
->will($this->returnValue($backend1)); |
|
|
|
|
|
|
|
|
|
$backend2 = $this->createMock(IBackend::class); |
|
|
|
|
$backend2->method('getBackendIdentifier')->will($this->returnValue('backend_2')); |
|
|
|
|
\OC::$server->registerService('calendar_resource_backend2', function () use ($backend2) { |
|
|
|
|
return $backend2; |
|
|
|
|
}); |
|
|
|
|
$this->server->expects($this->at(1)) |
|
|
|
|
->method('query') |
|
|
|
|
->with('calendar_resource_backend2') |
|
|
|
|
->will($this->returnValue($backend2)); |
|
|
|
|
|
|
|
|
|
$this->manager->registerBackend('calendar_resource_backend1'); |
|
|
|
|
$this->manager->registerBackend('calendar_resource_backend2'); |
|
|
|
|
|