forked from friendica/deprecated-addons
moved deprecated communityhome, dav and yourls to the deprecated-addons repository
This commit is contained in:
parent
24444adef3
commit
31520f804d
675 changed files with 195144 additions and 0 deletions
245
dav/SabreDAV/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php
Normal file
245
dav/SabreDAV/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php
Normal file
|
@ -0,0 +1,245 @@
|
|||
<?php
|
||||
|
||||
abstract class Sabre_CardDAV_Backend_AbstractPDOTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @var Sabre_CardDAV_Backend_PDO
|
||||
*/
|
||||
protected $backend;
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @return PDO
|
||||
*/
|
||||
abstract function getPDO();
|
||||
|
||||
public function setUp() {
|
||||
|
||||
$this->backend = new Sabre_CardDAV_Backend_PDO($this->getPDO());
|
||||
|
||||
}
|
||||
|
||||
public function testGetAddressBooksForUser() {
|
||||
|
||||
$result = $this->backend->getAddressBooksForUser('principals/user1');
|
||||
|
||||
$expected = array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'uri' => 'book1',
|
||||
'principaluri' => 'principals/user1',
|
||||
'{DAV:}displayname' => 'book1',
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
|
||||
'{http://calendarserver.org/ns/}getctag' => 1,
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' => new Sabre_CardDAV_Property_SupportedAddressData(),
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
}
|
||||
|
||||
public function testUpdateAddressBookInvalidProp() {
|
||||
|
||||
$result = $this->backend->updateAddressBook(1, array(
|
||||
'{DAV:}displayname' => 'updated',
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'updated',
|
||||
'{DAV:}foo' => 'bar',
|
||||
));
|
||||
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = $this->backend->getAddressBooksForUser('principals/user1');
|
||||
|
||||
$expected = array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'uri' => 'book1',
|
||||
'principaluri' => 'principals/user1',
|
||||
'{DAV:}displayname' => 'book1',
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
|
||||
'{http://calendarserver.org/ns/}getctag' => 1,
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' => new Sabre_CardDAV_Property_SupportedAddressData(),
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
}
|
||||
|
||||
public function testUpdateAddressBookNoProps() {
|
||||
|
||||
$result = $this->backend->updateAddressBook(1, array());
|
||||
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = $this->backend->getAddressBooksForUser('principals/user1');
|
||||
|
||||
$expected = array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'uri' => 'book1',
|
||||
'principaluri' => 'principals/user1',
|
||||
'{DAV:}displayname' => 'book1',
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
|
||||
'{http://calendarserver.org/ns/}getctag' => 1,
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' => new Sabre_CardDAV_Property_SupportedAddressData(),
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function testUpdateAddressBookSuccess() {
|
||||
|
||||
$result = $this->backend->updateAddressBook(1, array(
|
||||
'{DAV:}displayname' => 'updated',
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'updated',
|
||||
));
|
||||
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->backend->getAddressBooksForUser('principals/user1');
|
||||
|
||||
$expected = array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'uri' => 'book1',
|
||||
'principaluri' => 'principals/user1',
|
||||
'{DAV:}displayname' => 'updated',
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'updated',
|
||||
'{http://calendarserver.org/ns/}getctag' => 2,
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' => new Sabre_CardDAV_Property_SupportedAddressData(),
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function testDeleteAddressBook() {
|
||||
|
||||
$this->backend->deleteAddressBook(1);
|
||||
|
||||
$this->assertEquals(array(), $this->backend->getAddressBooksForUser('principals/user1'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre_DAV_Exception_BadRequest
|
||||
*/
|
||||
public function testCreateAddressBookUnsupportedProp() {
|
||||
|
||||
$this->backend->createAddressBook('principals/user1','book2', array(
|
||||
'{DAV:}foo' => 'bar',
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
public function testCreateAddressBookSuccess() {
|
||||
|
||||
$this->backend->createAddressBook('principals/user1','book2', array(
|
||||
'{DAV:}displayname' => 'book2',
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 2',
|
||||
));
|
||||
|
||||
$expected = array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'uri' => 'book1',
|
||||
'principaluri' => 'principals/user1',
|
||||
'{DAV:}displayname' => 'book1',
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
|
||||
'{http://calendarserver.org/ns/}getctag' => 1,
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' => new Sabre_CardDAV_Property_SupportedAddressData(),
|
||||
),
|
||||
array(
|
||||
'id' => 2,
|
||||
'uri' => 'book2',
|
||||
'principaluri' => 'principals/user1',
|
||||
'{DAV:}displayname' => 'book2',
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 2',
|
||||
'{http://calendarserver.org/ns/}getctag' => 1,
|
||||
'{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' => new Sabre_CardDAV_Property_SupportedAddressData(),
|
||||
)
|
||||
);
|
||||
$result = $this->backend->getAddressBooksForUser('principals/user1');
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
}
|
||||
|
||||
public function testGetCards() {
|
||||
|
||||
$result = $this->backend->getCards(1);
|
||||
|
||||
$expected = array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'uri' => 'card1',
|
||||
'carddata' => 'card1',
|
||||
'lastmodified' => 0,
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
}
|
||||
|
||||
public function testGetCard() {
|
||||
|
||||
$result = $this->backend->getCard(1,'card1');
|
||||
|
||||
$expected = array(
|
||||
'id' => 1,
|
||||
'uri' => 'card1',
|
||||
'carddata' => 'card1',
|
||||
'lastmodified' => 0,
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetCard
|
||||
*/
|
||||
public function testUpdateCard() {
|
||||
|
||||
$result = $this->backend->updateCard(1, 'card1', 'newdata');
|
||||
$this->assertEquals('"' . md5('newdata') . '"', $result);
|
||||
|
||||
$result = $this->backend->getCard(1,'card1');
|
||||
$this->assertEquals(1, $result['id']);
|
||||
$this->assertEquals('newdata', $result['carddata']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetCard
|
||||
*/
|
||||
public function testDeleteCard() {
|
||||
|
||||
$this->backend->deleteCard(1, 'card1');
|
||||
$result = $this->backend->getCard(1,'card1');
|
||||
$this->assertFalse($result);
|
||||
|
||||
}
|
||||
}
|
||||
|
125
dav/SabreDAV/tests/Sabre/CardDAV/Backend/Mock.php
Normal file
125
dav/SabreDAV/tests/Sabre/CardDAV/Backend/Mock.php
Normal file
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
|
||||
class Sabre_CardDAV_Backend_Mock extends Sabre_CardDAV_Backend_Abstract {
|
||||
|
||||
public $addressBooks;
|
||||
public $cards;
|
||||
|
||||
function __construct($addressBooks = null, $cards = null) {
|
||||
|
||||
$this->addressBooks = $addressBooks;
|
||||
$this->cards = $cards;
|
||||
|
||||
if (is_null($this->addressBooks)) {
|
||||
$this->addressBooks = array(
|
||||
array(
|
||||
'id' => 'foo',
|
||||
'uri' => 'book1',
|
||||
'principaluri' => 'principals/user1',
|
||||
'{DAV:}displayname' => 'd-name',
|
||||
),
|
||||
);
|
||||
|
||||
$this->cards = array(
|
||||
'foo' => array(
|
||||
'card1' => "BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD",
|
||||
'card2' => "BEGIN:VCARD\nVERSION:3.0\nUID:45678\nEND:VCARD",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function getAddressBooksForUser($principalUri) {
|
||||
|
||||
$books = array();
|
||||
foreach($this->addressBooks as $book) {
|
||||
if ($book['principaluri'] === $principalUri) {
|
||||
$books[] = $book;
|
||||
}
|
||||
}
|
||||
return $books;
|
||||
|
||||
}
|
||||
|
||||
function updateAddressBook($addressBookId, array $mutations) {
|
||||
|
||||
foreach($this->addressBooks as &$book) {
|
||||
if ($book['id'] !== $addressBookId)
|
||||
continue;
|
||||
|
||||
foreach($mutations as $key=>$value) {
|
||||
$book[$key] = $value;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
function createAddressBook($principalUri, $url, array $properties) {
|
||||
|
||||
$this->addressBooks[] = array_merge($properties, array(
|
||||
'id' => $url,
|
||||
'uri' => $url,
|
||||
'principaluri' => $principalUri,
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
function deleteAddressBook($addressBookId) {
|
||||
|
||||
foreach($this->addressBooks as $key=>$value) {
|
||||
if ($value['id'] === $addressBookId)
|
||||
unset($this->addressBooks[$key]);
|
||||
}
|
||||
unset($this->cards[$addressBookId]);
|
||||
|
||||
}
|
||||
|
||||
function getCards($addressBookId) {
|
||||
|
||||
$cards = array();
|
||||
foreach($this->cards[$addressBookId] as $uri=>$data) {
|
||||
$cards[] = array(
|
||||
'uri' => $uri,
|
||||
'carddata' => $data,
|
||||
);
|
||||
}
|
||||
return $cards;
|
||||
|
||||
}
|
||||
|
||||
function getCard($addressBookId, $cardUri) {
|
||||
|
||||
if (!isset($this->cards[$addressBookId][$cardUri])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return array(
|
||||
'uri' => $cardUri,
|
||||
'carddata' => $this->cards[$addressBookId][$cardUri],
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function createCard($addressBookId, $cardUri, $cardData) {
|
||||
|
||||
$this->cards[$addressBookId][$cardUri] = $cardData;
|
||||
|
||||
}
|
||||
|
||||
function updateCard($addressBookId, $cardUri, $cardData) {
|
||||
|
||||
$this->cards[$addressBookId][$cardUri] = $cardData;
|
||||
|
||||
}
|
||||
|
||||
function deleteCard($addressBookId, $cardUri) {
|
||||
|
||||
unset($this->cards[$addressBookId][$cardUri]);
|
||||
|
||||
}
|
||||
|
||||
}
|
58
dav/SabreDAV/tests/Sabre/CardDAV/Backend/PDOMySQLTest.php
Normal file
58
dav/SabreDAV/tests/Sabre/CardDAV/Backend/PDOMySQLTest.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
require_once 'Sabre/TestUtil.php';
|
||||
|
||||
class Sabre_CardDAV_Backend_PDOMySQLTest extends Sabre_CardDAV_Backend_AbstractPDOTest {
|
||||
|
||||
/**
|
||||
* @return PDO
|
||||
*/
|
||||
public function getPDO() {
|
||||
|
||||
if (!SABRE_HASMYSQL) $this->markTestSkipped('MySQL driver is not available, or not properly configured');
|
||||
|
||||
$pdo = Sabre_TestUtil::getMySQLDB();
|
||||
if (!$pdo) $this->markTestSkipped('Could not connect to MySQL database');
|
||||
|
||||
$pdo->query("DROP TABLE IF EXISTS addressbooks");
|
||||
$pdo->query("DROP TABLE IF EXISTS cards");
|
||||
$pdo->query("
|
||||
CREATE TABLE addressbooks (
|
||||
id INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
principaluri VARCHAR(255),
|
||||
displayname VARCHAR(255),
|
||||
uri VARCHAR(100),
|
||||
description TEXT,
|
||||
ctag INT(11) UNSIGNED NOT NULL DEFAULT '1'
|
||||
);
|
||||
");
|
||||
|
||||
$pdo->query("
|
||||
INSERT INTO addressbooks
|
||||
(principaluri, displayname, uri, description, ctag)
|
||||
VALUES
|
||||
('principals/user1', 'book1', 'book1', 'addressbook 1', 1);
|
||||
");
|
||||
|
||||
$pdo->query("
|
||||
CREATE TABLE cards (
|
||||
id INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
addressbookid INT(11) UNSIGNED NOT NULL,
|
||||
carddata TEXT,
|
||||
uri VARCHAR(100),
|
||||
lastmodified INT(11) UNSIGNED
|
||||
);
|
||||
");
|
||||
|
||||
$pdo->query("
|
||||
INSERT INTO cards
|
||||
(addressbookid, carddata, uri, lastmodified)
|
||||
VALUES
|
||||
(1, 'card1', 'card1', 0);
|
||||
");
|
||||
return $pdo;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
67
dav/SabreDAV/tests/Sabre/CardDAV/Backend/PDOSqliteTest.php
Normal file
67
dav/SabreDAV/tests/Sabre/CardDAV/Backend/PDOSqliteTest.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
require_once 'Sabre/TestUtil.php';
|
||||
|
||||
class Sabre_CardDAV_Backend_PDOSqliteTest extends Sabre_CardDAV_Backend_AbstractPDOTest {
|
||||
|
||||
function tearDown() {
|
||||
|
||||
if (file_exists(SABRE_TEMPDIR . '/pdobackend')) unlink(SABRE_TEMPDIR . '/pdobackend');
|
||||
if (file_exists(SABRE_TEMPDIR . '/pdobackend2')) unlink(SABRE_TEMPDIR . '/pdobackend2');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PDO
|
||||
*/
|
||||
function getPDO() {
|
||||
|
||||
if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
|
||||
$pdo = new PDO('sqlite:'.SABRE_TEMPDIR.'/pdobackend');
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
$pdo->query("DROP TABLE IF EXISTS addressbooks");
|
||||
$pdo->query("DROP TABLE IF EXISTS cards");
|
||||
$pdo->query("
|
||||
CREATE TABLE addressbooks (
|
||||
id integer primary key asc,
|
||||
principaluri text,
|
||||
displayname text,
|
||||
uri text,
|
||||
description text,
|
||||
ctag integer
|
||||
);
|
||||
|
||||
");
|
||||
|
||||
$pdo->query("
|
||||
INSERT INTO addressbooks
|
||||
(principaluri, displayname, uri, description, ctag)
|
||||
VALUES
|
||||
('principals/user1', 'book1', 'book1', 'addressbook 1', 1);
|
||||
");
|
||||
|
||||
$pdo->query("
|
||||
|
||||
CREATE TABLE cards (
|
||||
id integer primary key asc,
|
||||
addressbookid integer,
|
||||
carddata text,
|
||||
uri text,
|
||||
lastmodified integer
|
||||
);
|
||||
|
||||
");
|
||||
$pdo->query("
|
||||
INSERT INTO cards
|
||||
(addressbookid, carddata, uri, lastmodified)
|
||||
VALUES
|
||||
(1, 'card1', 'card1', 0);
|
||||
");
|
||||
|
||||
return $pdo;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue