示例#1
0
 /**
  * @param int $addressBookId
  * @param int $newAddressBookId
  */
 private function migrateShares($addressBookId, $newAddressBookId)
 {
     $shares = $this->adapter->getShares($addressBookId);
     if (empty($shares)) {
         return;
     }
     $add = array_map(function ($s) {
         $prefix = 'principal:principals/users/';
         if ($s['share_type'] === 1) {
             $prefix = 'principal:principals/groups/';
         }
         return ['href' => $prefix . $s['share_with']];
     }, $shares);
     $newAddressBook = $this->backend->getAddressBookById($newAddressBookId);
     $book = new AddressBook($this->backend, $newAddressBook);
     $this->backend->updateShares($book, $add, []);
 }
 public function testSharing()
 {
     $this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
     $books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER);
     $this->assertEquals(1, count($books));
     $this->backend->updateShares('Example', [['href' => 'principal:principals/best-friend']], []);
     $shares = $this->backend->getShares('Example');
     $this->assertEquals(1, count($shares));
     // adding the same sharee again has no effect
     $this->backend->updateShares('Example', [['href' => 'principal:principals/best-friend']], []);
     $shares = $this->backend->getShares('Example');
     $this->assertEquals(1, count($shares));
     $books = $this->backend->getAddressBooksForUser('principals/best-friend');
     $this->assertEquals(1, count($books));
     $this->backend->updateShares('Example', [], [['href' => 'principal:principals/best-friend']]);
     $shares = $this->backend->getShares('Example');
     $this->assertEquals(0, count($shares));
     $books = $this->backend->getAddressBooksForUser('principals/best-friend');
     $this->assertEquals(0, count($books));
 }