diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2017-05-02 14:32:26 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2017-05-08 11:20:47 +0200 |
commit | 303c0dd6a8d2f614841b4ebdacff9ced7120a9e3 (patch) | |
tree | f1fb87da19d97755d60fd61b0cffbef94684fc4e /apps/dav/tests | |
parent | 4d7a96bc85b9a114daf9fb027a483daf26905b25 (diff) | |
download | nextcloud-server-303c0dd6a8d2f614841b4ebdacff9ced7120a9e3.tar.gz nextcloud-server-303c0dd6a8d2f614841b4ebdacff9ced7120a9e3.zip |
Always dispatch Carddav events
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/dav/tests')
-rw-r--r-- | apps/dav/tests/unit/CardDAV/CardDavBackendTest.php | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php index c108432d65b..f3a271a2db2 100644 --- a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php +++ b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php @@ -34,9 +34,12 @@ use OCA\DAV\Connector\Sabre\Principal; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; use OCP\IL10N; +use OCP\IUserManager; use Sabre\DAV\PropPatch; use Sabre\VObject\Component\VCard; use Sabre\VObject\Property\Text; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\GenericEvent; use Test\TestCase; /** @@ -54,9 +57,12 @@ class CardDavBackendTest extends TestCase { /** @var Principal | \PHPUnit_Framework_MockObject_MockObject */ private $principal; - /** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject */ + /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ private $userManager; + /** @var EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */ + private $dispatcher; + /** @var IDBConnection */ private $db; @@ -73,9 +79,7 @@ class CardDavBackendTest extends TestCase { public function setUp() { parent::setUp(); - $this->userManager = $this->getMockBuilder('OCP\IUserManager') - ->disableOriginalConstructor() - ->getMock(); + $this->userManager = $this->createMock(IUserManager::class); $this->principal = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Principal') ->disableOriginalConstructor() ->setMethods(['getPrincipalByPath', 'getGroupMembership']) @@ -88,11 +92,11 @@ class CardDavBackendTest extends TestCase { $this->principal->method('getGroupMembership') ->withAnyParameters() ->willReturn([self::UNIT_TEST_GROUP]); + $this->dispatcher = $this->createMock(EventDispatcherInterface::class); $this->db = \OC::$server->getDatabaseConnection(); - $this->backend = new CardDavBackend($this->db, $this->principal, $this->userManager, null); - + $this->backend = new CardDavBackend($this->db, $this->principal, $this->userManager, $this->dispatcher); // start every test with a empty cards_properties and cards table $query = $this->db->getQueryBuilder(); $query->delete('cards_properties')->execute(); @@ -172,7 +176,7 @@ class CardDavBackendTest extends TestCase { /** @var CardDavBackend | \PHPUnit_Framework_MockObject_MockObject $backend */ $backend = $this->getMockBuilder(CardDavBackend::class) - ->setConstructorArgs([$this->db, $this->principal, $this->userManager, null]) + ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->dispatcher]) ->setMethods(['updateProperties', 'purgeProperties'])->getMock(); // create a new address book @@ -185,6 +189,16 @@ class CardDavBackendTest extends TestCase { // updateProperties is expected twice, once for createCard and once for updateCard $backend->expects($this->at(0))->method('updateProperties')->with($bookId, $uri, ''); $backend->expects($this->at(1))->method('updateProperties')->with($bookId, $uri, '***'); + + // Expect event + $this->dispatcher->expects($this->at(0)) + ->method('dispatch') + ->with('\OCA\DAV\CardDAV\CardDavBackend::createCard', $this->callback(function(GenericEvent $e) use ($bookId, $uri) { + return $e->getArgument('addressBookId') === $bookId && + $e->getArgument('cardUri') === $uri && + $e->getArgument('cardData') === ''; + })); + // create a card $backend->createCard($bookId, $uri, ''); @@ -203,11 +217,28 @@ class CardDavBackendTest extends TestCase { $this->assertArrayHasKey('size', $card); $this->assertEquals('', $card['carddata']); + // Expect event + $this->dispatcher->expects($this->at(0)) + ->method('dispatch') + ->with('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $this->callback(function(GenericEvent $e) use ($bookId, $uri) { + return $e->getArgument('addressBookId') === $bookId && + $e->getArgument('cardUri') === $uri && + $e->getArgument('cardData') === '***'; + })); + // update the card $backend->updateCard($bookId, $uri, '***'); $card = $backend->getCard($bookId, $uri); $this->assertEquals('***', $card['carddata']); + // Expect event + $this->dispatcher->expects($this->at(0)) + ->method('dispatch') + ->with('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $this->callback(function(GenericEvent $e) use ($bookId, $uri) { + return $e->getArgument('addressBookId') === $bookId && + $e->getArgument('cardUri') === $uri; + })); + // delete the card $backend->expects($this->once())->method('purgeProperties')->with($bookId, $card['id']); $backend->deleteCard($bookId, $uri); @@ -218,7 +249,7 @@ class CardDavBackendTest extends TestCase { public function testMultiCard() { $this->backend = $this->getMockBuilder(CardDavBackend::class) - ->setConstructorArgs([$this->db, $this->principal, $this->userManager, null]) + ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->dispatcher]) ->setMethods(['updateProperties'])->getMock(); // create a new address book @@ -264,7 +295,7 @@ class CardDavBackendTest extends TestCase { public function testDeleteWithoutCard() { $this->backend = $this->getMockBuilder(CardDavBackend::class) - ->setConstructorArgs([$this->db, $this->principal, $this->userManager, null]) + ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->dispatcher]) ->setMethods([ 'getCardId', 'addChange', @@ -304,7 +335,7 @@ class CardDavBackendTest extends TestCase { public function testSyncSupport() { $this->backend = $this->getMockBuilder(CardDavBackend::class) - ->setConstructorArgs([$this->db, $this->principal, $this->userManager, null]) + ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->dispatcher]) ->setMethods(['updateProperties'])->getMock(); // create a new address book @@ -363,7 +394,7 @@ class CardDavBackendTest extends TestCase { $cardId = 2; $backend = $this->getMockBuilder(CardDavBackend::class) - ->setConstructorArgs([$this->db, $this->principal, $this->userManager, null]) + ->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->dispatcher]) ->setMethods(['getCardId'])->getMock(); $backend->expects($this->any())->method('getCardId')->willReturn($cardId); |