aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2016-05-28 17:46:24 +0200
committerMario Vavti <mario@mariovavti.com>2016-05-28 17:46:24 +0200
commit66effbfe0827fc61fff6d248797a894213ad20d6 (patch)
tree0fbb5ca644e1140e5b3b44b1adc874043790c388 /vendor/sabre/dav/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php
parentac4688eac087854bf8cb0c893d7a79052ad63a20 (diff)
downloadvolse-hubzilla-66effbfe0827fc61fff6d248797a894213ad20d6.tar.gz
volse-hubzilla-66effbfe0827fc61fff6d248797a894213ad20d6.tar.bz2
volse-hubzilla-66effbfe0827fc61fff6d248797a894213ad20d6.zip
upgrade to sabre32
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php')
-rw-r--r--vendor/sabre/dav/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php275
1 files changed, 149 insertions, 126 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php
index d2ec278be..f62bfb1ae 100644
--- a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php
+++ b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php
@@ -7,52 +7,55 @@ use Sabre\DAV\PropPatch;
abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
+ use \Sabre\DAV\DbTestHelperTrait;
+
/**
* @var CardDAV\Backend\PDO
*/
protected $backend;
- /**
- * @abstract
- * @return PDO
- */
- abstract function getPDO();
-
- public function setUp() {
+ function setUp() {
+ $this->dropTables([
+ 'addressbooks',
+ 'cards',
+ 'addressbookchanges',
+ ]);
+ $this->createSchema('addressbooks');
$pdo = $this->getPDO();
+
$this->backend = new PDO($pdo);
- $pdo->exec('INSERT INTO addressbooks (principaluri, displayname, uri, description, synctoken) VALUES ("principals/user1", "book1", "book1", "addressbook 1", 1)');
- $pdo->exec('INSERT INTO cards (addressbookid, carddata, uri, lastmodified, etag, size) VALUES (1, "card1", "card1", 0, "' . md5('card1') . '", 5)');
+ $pdo->exec("INSERT INTO addressbooks (principaluri, displayname, uri, description, synctoken) VALUES ('principals/user1', 'book1', 'book1', 'addressbook 1', 1)");
+ $pdo->exec("INSERT INTO cards (addressbookid, carddata, uri, lastmodified, etag, size) VALUES (1, 'card1', 'card1', 0, '" . md5('card1') . "', 5)");
}
- public function testGetAddressBooksForUser() {
+ function testGetAddressBooksForUser() {
$result = $this->backend->getAddressBooksForUser('principals/user1');
- $expected = array(
- array(
- 'id' => 1,
- 'uri' => 'book1',
- 'principaluri' => 'principals/user1',
- '{DAV:}displayname' => 'book1',
+ $expected = [
+ [
+ 'id' => 1,
+ 'uri' => 'book1',
+ 'principaluri' => 'principals/user1',
+ '{DAV:}displayname' => 'book1',
'{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
- '{http://calendarserver.org/ns/}getctag' => 1,
- '{http://sabredav.org/ns}sync-token' => 1
- )
- );
+ '{http://calendarserver.org/ns/}getctag' => 1,
+ '{http://sabredav.org/ns}sync-token' => 1
+ ]
+ ];
$this->assertEquals($expected, $result);
}
- public function testUpdateAddressBookInvalidProp() {
+ function testUpdateAddressBookInvalidProp() {
$propPatch = new PropPatch([
- '{DAV:}displayname' => 'updated',
+ '{DAV:}displayname' => 'updated',
'{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'updated',
- '{DAV:}foo' => 'bar',
+ '{DAV:}foo' => 'bar',
]);
$this->backend->updateAddressBook(1, $propPatch);
@@ -62,23 +65,23 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$result = $this->backend->getAddressBooksForUser('principals/user1');
- $expected = array(
- array(
- 'id' => 1,
- 'uri' => 'book1',
- 'principaluri' => 'principals/user1',
- '{DAV:}displayname' => 'book1',
+ $expected = [
+ [
+ 'id' => 1,
+ 'uri' => 'book1',
+ 'principaluri' => 'principals/user1',
+ '{DAV:}displayname' => 'book1',
'{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
- '{http://calendarserver.org/ns/}getctag' => 1,
- '{http://sabredav.org/ns}sync-token' => 1
- )
- );
+ '{http://calendarserver.org/ns/}getctag' => 1,
+ '{http://sabredav.org/ns}sync-token' => 1
+ ]
+ ];
$this->assertEquals($expected, $result);
}
- public function testUpdateAddressBookNoProps() {
+ function testUpdateAddressBookNoProps() {
$propPatch = new PropPatch([
]);
@@ -89,27 +92,27 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$result = $this->backend->getAddressBooksForUser('principals/user1');
- $expected = array(
- array(
- 'id' => 1,
- 'uri' => 'book1',
- 'principaluri' => 'principals/user1',
- '{DAV:}displayname' => 'book1',
+ $expected = [
+ [
+ 'id' => 1,
+ 'uri' => 'book1',
+ 'principaluri' => 'principals/user1',
+ '{DAV:}displayname' => 'book1',
'{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
- '{http://calendarserver.org/ns/}getctag' => 1,
- '{http://sabredav.org/ns}sync-token' => 1
- )
- );
+ '{http://calendarserver.org/ns/}getctag' => 1,
+ '{http://sabredav.org/ns}sync-token' => 1
+ ]
+ ];
$this->assertEquals($expected, $result);
}
- public function testUpdateAddressBookSuccess() {
+ function testUpdateAddressBookSuccess() {
$propPatch = new PropPatch([
- '{DAV:}displayname' => 'updated',
+ '{DAV:}displayname' => 'updated',
'{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'updated',
]);
@@ -120,104 +123,108 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$result = $this->backend->getAddressBooksForUser('principals/user1');
- $expected = array(
- array(
- 'id' => 1,
- 'uri' => 'book1',
- 'principaluri' => 'principals/user1',
- '{DAV:}displayname' => 'updated',
+ $expected = [
+ [
+ 'id' => 1,
+ 'uri' => 'book1',
+ 'principaluri' => 'principals/user1',
+ '{DAV:}displayname' => 'updated',
'{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'updated',
- '{http://calendarserver.org/ns/}getctag' => 2,
- '{http://sabredav.org/ns}sync-token' => 2
- )
- );
+ '{http://calendarserver.org/ns/}getctag' => 2,
+ '{http://sabredav.org/ns}sync-token' => 2
+ ]
+ ];
$this->assertEquals($expected, $result);
}
- public function testDeleteAddressBook() {
+ function testDeleteAddressBook() {
$this->backend->deleteAddressBook(1);
- $this->assertEquals(array(), $this->backend->getAddressBooksForUser('principals/user1'));
+ $this->assertEquals([], $this->backend->getAddressBooksForUser('principals/user1'));
}
/**
* @expectedException Sabre\DAV\Exception\BadRequest
*/
- public function testCreateAddressBookUnsupportedProp() {
+ function testCreateAddressBookUnsupportedProp() {
- $this->backend->createAddressBook('principals/user1','book2', array(
+ $this->backend->createAddressBook('principals/user1', 'book2', [
'{DAV:}foo' => 'bar',
- ));
+ ]);
}
- public function testCreateAddressBookSuccess() {
+ function testCreateAddressBookSuccess() {
- $this->backend->createAddressBook('principals/user1','book2', array(
- '{DAV:}displayname' => 'book2',
+ $this->backend->createAddressBook('principals/user1', 'book2', [
+ '{DAV:}displayname' => 'book2',
'{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 2',
- ));
-
- $expected = array(
- array(
- 'id' => 1,
- 'uri' => 'book1',
- 'principaluri' => 'principals/user1',
- '{DAV:}displayname' => 'book1',
+ ]);
+
+ $expected = [
+ [
+ 'id' => 1,
+ 'uri' => 'book1',
+ 'principaluri' => 'principals/user1',
+ '{DAV:}displayname' => 'book1',
'{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
- '{http://calendarserver.org/ns/}getctag' => 1,
- '{http://sabredav.org/ns}sync-token' => 1,
- ),
- array(
- 'id' => 2,
- 'uri' => 'book2',
- 'principaluri' => 'principals/user1',
- '{DAV:}displayname' => 'book2',
+ '{http://calendarserver.org/ns/}getctag' => 1,
+ '{http://sabredav.org/ns}sync-token' => 1,
+ ],
+ [
+ 'id' => 2,
+ 'uri' => 'book2',
+ 'principaluri' => 'principals/user1',
+ '{DAV:}displayname' => 'book2',
'{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 2',
- '{http://calendarserver.org/ns/}getctag' => 1,
- '{http://sabredav.org/ns}sync-token' => 1,
- )
- );
+ '{http://calendarserver.org/ns/}getctag' => 1,
+ '{http://sabredav.org/ns}sync-token' => 1,
+ ]
+ ];
$result = $this->backend->getAddressBooksForUser('principals/user1');
$this->assertEquals($expected, $result);
}
- public function testGetCards() {
+ function testGetCards() {
$result = $this->backend->getCards(1);
- $expected = array(
- array(
- 'id' => 1,
- 'uri' => 'card1',
+ $expected = [
+ [
+ 'id' => 1,
+ 'uri' => 'card1',
'lastmodified' => 0,
- 'etag' => '"' . md5('card1') . '"',
- 'size' => 5
- )
- );
+ 'etag' => '"' . md5('card1') . '"',
+ 'size' => 5
+ ]
+ ];
$this->assertEquals($expected, $result);
}
- public function testGetCard() {
+ function testGetCard() {
- $result = $this->backend->getCard(1,'card1');
+ $result = $this->backend->getCard(1, 'card1');
- $expected = array(
- 'id' => 1,
- 'uri' => 'card1',
- 'carddata' => 'card1',
+ $expected = [
+ 'id' => 1,
+ 'uri' => 'card1',
+ 'carddata' => 'card1',
'lastmodified' => 0,
- 'etag' => '"' . md5('card1') . '"',
- 'size' => 5
- );
+ 'etag' => '"' . md5('card1') . '"',
+ 'size' => 5
+ ];
+
+ if (is_resource($result['carddata'])) {
+ $result['carddata'] = stream_get_contents($result['carddata']);
+ }
$this->assertEquals($expected, $result);
@@ -226,13 +233,16 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
/**
* @depends testGetCard
*/
- public function testCreateCard() {
+ function testCreateCard() {
$result = $this->backend->createCard(1, 'card2', 'data2');
$this->assertEquals('"' . md5('data2') . '"', $result);
- $result = $this->backend->getCard(1,'card2');
+ $result = $this->backend->getCard(1, 'card2');
$this->assertEquals(2, $result['id']);
$this->assertEquals('card2', $result['uri']);
+ if (is_resource($result['carddata'])) {
+ $result['carddata'] = stream_get_contents($result['carddata']);
+ }
$this->assertEquals('data2', $result['carddata']);
}
@@ -240,41 +250,52 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
/**
* @depends testCreateCard
*/
- public function testGetMultiple() {
+ function testGetMultiple() {
$result = $this->backend->createCard(1, 'card2', 'data2');
$result = $this->backend->createCard(1, 'card3', 'data3');
$check = [
[
- 'id' => 1,
- 'uri' => 'card1',
- 'carddata' => 'card1',
+ 'id' => 1,
+ 'uri' => 'card1',
+ 'carddata' => 'card1',
'lastmodified' => 0,
],
[
- 'id' => 2,
- 'uri' => 'card2',
- 'carddata' => 'data2',
+ 'id' => 2,
+ 'uri' => 'card2',
+ 'carddata' => 'data2',
'lastmodified' => time(),
],
[
- 'id' => 3,
- 'uri' => 'card3',
- 'carddata' => 'data3',
+ 'id' => 3,
+ 'uri' => 'card3',
+ 'carddata' => 'data3',
'lastmodified' => time(),
],
];
- $result = $this->backend->getMultipleCards(1, ['card1','card2','card3']);
+ $result = $this->backend->getMultipleCards(1, ['card1', 'card2', 'card3']);
+
+ foreach ($check as $index => $node) {
- foreach($check as $index=>$node) {
+ foreach ($node as $k => $v) {
- foreach($node as $k=>$v) {
+ $expected = $v;
+ $actual = $result[$index][$k];
- if ($k!=='lastmodified') {
- $this->assertEquals($v, $result[$index][$k]);
- } else {
- $this->assertTrue(isset($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.
+ default :
+ $this->assertEquals($expected, $actual);
+ break;
}
}
@@ -287,13 +308,16 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
/**
* @depends testGetCard
*/
- public function testUpdateCard() {
+ function testUpdateCard() {
$result = $this->backend->updateCard(1, 'card1', 'newdata');
$this->assertEquals('"' . md5('newdata') . '"', $result);
- $result = $this->backend->getCard(1,'card1');
+ $result = $this->backend->getCard(1, 'card1');
$this->assertEquals(1, $result['id']);
+ if (is_resource($result['carddata'])) {
+ $result['carddata'] = stream_get_contents($result['carddata']);
+ }
$this->assertEquals('newdata', $result['carddata']);
}
@@ -301,10 +325,10 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
/**
* @depends testGetCard
*/
- public function testDeleteCard() {
+ function testDeleteCard() {
$this->backend->deleteCard(1, 'card1');
- $result = $this->backend->getCard(1,'card1');
+ $result = $this->backend->getCard(1, 'card1');
$this->assertFalse($result);
}
@@ -347,4 +371,3 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
}
}
-