createCard() публичный Метод

The addressbook id will be passed as the first argument. This is the same id as it is returned from the getAddressBooksForUser method. The cardUri is a base uri, and doesn't include the full path. The cardData argument is the vcard body, and is passed as a string. It is possible to return an ETag from this method. This ETag is for the newly created resource, and must be enclosed with double quotes (that is, the string itself must contain the double quotes). You should only return the ETag if you store the carddata as-is. If a subsequent GET request on the same card does not have the same body, byte-by-byte and you did return an ETag here, clients tend to get confused. If you don't return an ETag, you can just return null.
public createCard ( mixed $addressBookId, string $cardUri, string $cardData ) : string | null
$addressBookId mixed
$cardUri string
$cardData string
Результат string | null
Пример #1
0
 /**
  * @depends testCreateCard
  */
 function testGetMultiple()
 {
     $result = $this->backend->createCard(1, 'card2', 'data2');
     $result = $this->backend->createCard(1, 'card3', 'data3');
     $check = [['id' => 1, 'uri' => 'card1', 'carddata' => 'card1', 'lastmodified' => 0], ['id' => 2, 'uri' => 'card2', 'carddata' => 'data2', 'lastmodified' => time()], ['id' => 3, 'uri' => 'card3', 'carddata' => 'data3', 'lastmodified' => time()]];
     $result = $this->backend->getMultipleCards(1, ['card1', 'card2', 'card3']);
     foreach ($check as $index => $node) {
         foreach ($node as $k => $v) {
             $expected = $v;
             $actual = $result[$index][$k];
             switch ($k) {
                 case 'lastmodified':
                     $this->assertInternalType('int', $actual);
                     break;
                 case 'carddata':
                     if (is_resource($actual)) {
                         $actual = stream_get_contents($actual);
                     }
                     // No break intended.
                 // No break intended.
                 default:
                     $this->assertEquals($expected, $actual);
                     break;
             }
         }
     }
 }
Пример #2
0
 /**
  * @depends testGetCard
  */
 public function testCreateCard()
 {
     $result = $this->backend->createCard(1, 'card2', 'data2');
     $this->assertEquals('"' . md5('data2') . '"', $result);
     $result = $this->backend->getCard(1, 'card2');
     $this->assertEquals(2, $result['id']);
     $this->assertEquals('card2', $result['uri']);
     $this->assertEquals('data2', $result['carddata']);
 }
 static function getSQLiteDB()
 {
     $pdo = Backend\PDOSqliteTest::getSQLite();
     // Inserting events through a backend class.
     $backend = new Backend\PDO($pdo);
     $addressbookId = $backend->createAddressBook('principals/user1', 'UUID-123467', array('{DAV:}displayname' => 'user1 addressbook', '{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'AddressBook description'));
     $backend->createAddressBook('principals/user1', 'UUID-123468', array('{DAV:}displayname' => 'user1 addressbook2', '{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'AddressBook description'));
     $backend->createCard($addressbookId, 'UUID-2345', self::getTestCardData());
     return $pdo;
 }
Пример #4
0
 /**
  * @depends testCreateCard
  */
 public function testGetMultiple()
 {
     $result = $this->backend->createCard(1, 'card2', 'data2');
     $result = $this->backend->createCard(1, 'card3', 'data3');
     $check = [['id' => 1, 'uri' => 'card1', 'carddata' => 'card1', 'lastmodified' => 0], ['id' => 2, 'uri' => 'card2', 'carddata' => 'data2', 'lastmodified' => time()], ['id' => 3, 'uri' => 'card3', 'carddata' => 'data3', 'lastmodified' => time()]];
     $result = $this->backend->getMultipleCards(1, ['card1', 'card2', 'card3']);
     foreach ($check as $index => $node) {
         foreach ($node as $k => $v) {
             if ($k !== 'lastmodified') {
                 $this->assertEquals($v, $result[$index][$k]);
             } else {
                 $this->assertTrue(isset($result[$index][$k]));
             }
         }
     }
 }
Пример #5
0
 static function getSQLiteDB()
 {
     if (file_exists(SABRE_TEMPDIR . '/testdb.sqlite')) {
         unlink(SABRE_TEMPDIR . '/testdb.sqlite');
     }
     $pdo = new PDO('sqlite:' . SABRE_TEMPDIR . '/testdb.sqlite');
     $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     // Yup this is definitely not 'fool proof', but good enough for now.
     $queries = explode(';', file_get_contents(__DIR__ . '/../../../examples/sql/sqlite.addressbooks.sql'));
     foreach ($queries as $query) {
         $pdo->exec($query);
     }
     // Inserting events through a backend class.
     $backend = new Backend\PDO($pdo);
     $addressbookId = $backend->createAddressBook('principals/user1', 'UUID-123467', array('{DAV:}displayname' => 'user1 addressbook', '{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'AddressBook description'));
     $backend->createAddressBook('principals/user1', 'UUID-123468', array('{DAV:}displayname' => 'user1 addressbook2', '{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'AddressBook description'));
     $backend->createCard($addressbookId, 'UUID-2345', self::getTestCardData());
     return $pdo;
 }