mirror of
https://github.com/owncloudarchive/contacts.git
synced 2024-11-29 11:24:11 +01:00
Last commit in master until travis starts working
This commit is contained in:
parent
26cfb42e3a
commit
4a3495aab4
@ -29,6 +29,6 @@ before_script:
|
||||
# - sudo ln -s $(pwd)/phantomjs-1.9.0-linux-x86_64/bin/phantomjs /usr/bin/phantomjs
|
||||
|
||||
script:
|
||||
- make unit-tests
|
||||
- phpunit --configuration tests/phpunit.xml
|
||||
|
||||
#&& make javascript-tests
|
||||
|
131
tests/lib/backend/mock.php
Normal file
131
tests/lib/backend/mock.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace OCA\Contacts\Backend;
|
||||
|
||||
class Mock extends AbstractBackend {
|
||||
|
||||
public $name = 'mock';
|
||||
public $addressBooks;
|
||||
public $contacts;
|
||||
|
||||
function __construct($userid = null, $addressBooks = null, $contacts = null) {
|
||||
|
||||
$this->userid = $userid ? $userid : \OCP\User::getUser();
|
||||
$this->addressBooks = $addressBooks;
|
||||
$this->contacts = $contacts;
|
||||
|
||||
if (is_null($this->addressBooks)) {
|
||||
$this->addressBooks = array(
|
||||
array(
|
||||
'id' => 'foo',
|
||||
'owner' => 'user1',
|
||||
'displayname' => 'd-name',
|
||||
),
|
||||
);
|
||||
|
||||
$card2 = fopen('php://memory','r+');
|
||||
fwrite($card2,"BEGIN:VCARD\nVERSION:3.0\nUID:45678\nEND:VCARD");
|
||||
rewind($card2);
|
||||
$this->contacts = array(
|
||||
'foo' => array(
|
||||
'card1' => "BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD",
|
||||
'card2' => $card2,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function getAddressBooksForUser($userid = null) {
|
||||
|
||||
$books = array();
|
||||
foreach($this->addressBooks as $book) {
|
||||
if ($book['owner'] === $userid) {
|
||||
$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->contacts[$addressBookId]);
|
||||
|
||||
}
|
||||
|
||||
function getContacts($addressBookId) {
|
||||
|
||||
$contacts = array();
|
||||
foreach($this->contacts[$addressBookId] as $uri=>$data) {
|
||||
$contacts[] = array(
|
||||
'uri' => $uri,
|
||||
'carddata' => $data,
|
||||
);
|
||||
}
|
||||
return $contacts;
|
||||
|
||||
}
|
||||
|
||||
function getContact($addressBookId, $id) {
|
||||
|
||||
if (!isset($this->contacts[$addressBookId][$id])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return array(
|
||||
'uri' => $id,
|
||||
'carddata' => $this->contacts[$addressBookId][$id],
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function createContact($addressBookId, $id, $contact) {
|
||||
|
||||
$this->contacts[$addressBookId][$id] = $contact;
|
||||
|
||||
}
|
||||
|
||||
function updateContact($addressBookId, $id, $contact) {
|
||||
|
||||
$this->contacts[$addressBookId][$id] = $contact;
|
||||
|
||||
}
|
||||
|
||||
function deleteContact($addressBookId, $id) {
|
||||
|
||||
unset($this->contacts[$addressBookId][$id]);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -15,7 +15,7 @@ class Test_Contacts_Backend_Datebase extends PHPUnit_Framework_TestCase {
|
||||
protected static $cardsTableName;
|
||||
|
||||
public static function setUpBeforeClass() {
|
||||
$dbfile = __DIR__.'/../appinfo/database.xml';
|
||||
$dbfile = __DIR__.'/../../appinfo/database.xml';
|
||||
|
||||
self::$test_prefix = '_'.OC_Util::generate_random_bytes('4').'_';
|
||||
$content = file_get_contents($dbfile);
|
||||
@ -71,14 +71,14 @@ class Test_Contacts_Backend_Datebase extends PHPUnit_Framework_TestCase {
|
||||
// Test contacts
|
||||
$this->assertEquals(array(), self::$backend->getContacts($aid));
|
||||
|
||||
$carddata = file_get_contents(__DIR__ . '/data/test1.vcf');
|
||||
$carddata = file_get_contents(__DIR__ . '/../data/test1.vcf');
|
||||
$id = self::$backend->createContact($aid, $carddata);
|
||||
$this->assertNotEquals(false, $id); // Isn't there an assertNotFalse() ?
|
||||
$this->assertEquals(1, count(self::$backend->getContacts($aid)));
|
||||
$this->assertTrue(self::$backend->hasContact($aid, $id));
|
||||
$contact = self::$backend->getContact($aid, $id);
|
||||
$this->assertEquals('Max Mustermann', $contact['displayname']);
|
||||
$carddata = file_get_contents(__DIR__ . '/data/test2.vcf');
|
||||
$carddata = file_get_contents(__DIR__ . '/../data/test2.vcf');
|
||||
$this->assertTrue(self::$backend->updateContact($aid, $id, $carddata));
|
||||
$contact = self::$backend->getContact($aid, $id);
|
||||
$this->assertEquals('John Q. Public', $contact['displayname']);
|
@ -19,7 +19,7 @@ class Test_VObject extends PHPUnit_Framework_TestCase {
|
||||
}*/
|
||||
|
||||
public function testCrappyVCard() {
|
||||
$carddata = file_get_contents(__DIR__ . '/data/test3.vcf');
|
||||
$carddata = file_get_contents(__DIR__ . '/../data/test3.vcf');
|
||||
$obj = \Sabre\VObject\Reader::read(
|
||||
$carddata,
|
||||
\Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES
|
@ -6,11 +6,10 @@
|
||||
strict="true"
|
||||
verbose="true"
|
||||
colors="true"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="contacts">
|
||||
<file>vobject.php</file>
|
||||
<file>contacts.php</file>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Contacts App">
|
||||
<directory suffix="_test.php">lib</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
|
Loading…
Reference in New Issue
Block a user