mirror of
https://github.com/owncloudarchive/contacts.git
synced 2024-12-10 21:24:33 +01:00
Merge pull request #578 from owncloud/fix-search-master
adding first unit test for search of address book provider
This commit is contained in:
commit
e40104f6e1
@ -10,13 +10,12 @@ branches:
|
|||||||
|
|
||||||
env:
|
env:
|
||||||
- DB=sqlite
|
- DB=sqlite
|
||||||
|
- DB=mysql
|
||||||
# - DB=mysql
|
|
||||||
# - DB=pgsql
|
# - DB=pgsql
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- ./tests/install_dependencies.sh
|
- wget https://raw.githubusercontent.com/owncloud/administration/master/travis-ci/before_install.sh
|
||||||
- tests/setup_owncloud.sh
|
- bash ./before_install.sh contacts master $DB
|
||||||
|
|
||||||
# - sudo add-apt-repository -y ppa:chris-lea/node.js
|
# - sudo add-apt-repository -y ppa:chris-lea/node.js
|
||||||
# - sudo apt-get update
|
# - sudo apt-get update
|
||||||
|
@ -6,7 +6,6 @@ $RUNTIME_NOAPPS = true;
|
|||||||
if(!defined('PHPUNIT_RUN')) {
|
if(!defined('PHPUNIT_RUN')) {
|
||||||
define('PHPUNIT_RUN', 1);
|
define('PHPUNIT_RUN', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once __DIR__.'/../../core/lib/base.php';
|
require_once __DIR__.'/../../core/lib/base.php';
|
||||||
|
|
||||||
if(!class_exists('PHPUnit_Framework_TestCase')) {
|
if(!class_exists('PHPUnit_Framework_TestCase')) {
|
||||||
@ -17,3 +16,5 @@ if(!class_exists('PHPUnit_Framework_TestCase')) {
|
|||||||
|
|
||||||
OC_Hook::clear();
|
OC_Hook::clear();
|
||||||
OC_Log::$enabled = true;
|
OC_Log::$enabled = true;
|
||||||
|
\OCP\Util::connectHook('OCA\Contacts', 'pre_deleteContact', '\OCA\Contacts\Hooks', 'contactDeletion');
|
||||||
|
|
||||||
|
@ -19,11 +19,11 @@ class AddressBookTest extends \PHPUnit_Framework_TestCase {
|
|||||||
*/
|
*/
|
||||||
protected $abinfo;
|
protected $abinfo;
|
||||||
/**
|
/**
|
||||||
* @var OCA\Contacts\AddressBook
|
* @var \OCA\Contacts\Addressbook
|
||||||
*/
|
*/
|
||||||
protected $ab;
|
protected $ab;
|
||||||
/**
|
/**
|
||||||
* @var OCA\Contacts\Backend\AbstractBackend
|
* @var \OCA\Contacts\Backend\AbstractBackend
|
||||||
*/
|
*/
|
||||||
protected $backend;
|
protected $backend;
|
||||||
|
|
||||||
|
83
tests/lib/addressbookprovider_test.php
Normal file
83
tests/lib/addressbookprovider_test.php
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2013 Thomas Tanghus (thomas@tanghus.net)
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later.
|
||||||
|
* See the COPYING-README file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCA\Contacts;
|
||||||
|
|
||||||
|
|
||||||
|
class AddressBookProviderTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $abinfo;
|
||||||
|
/**
|
||||||
|
* @var \OCA\Contacts\Addressbook
|
||||||
|
*/
|
||||||
|
protected $ab;
|
||||||
|
/**
|
||||||
|
* @var \OCA\Contacts\Backend\AbstractBackend
|
||||||
|
*/
|
||||||
|
protected $backend;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \OCA\Contacts\AddressbookProvider
|
||||||
|
*/
|
||||||
|
private $provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $contactIds = array();
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
|
||||||
|
\Sabre\VObject\Component::$classMap['VCARD'] = '\OCA\Contacts\VObject\VCard';
|
||||||
|
|
||||||
|
$user = uniqid('user_');
|
||||||
|
$this->backend = new Backend\Database($user);
|
||||||
|
$this->abinfo = array('displayname' => uniqid('display_'));
|
||||||
|
$this->ab = new AddressBook($this->backend, $this->abinfo);
|
||||||
|
|
||||||
|
$this->provider = new AddressbookProvider($this->ab);
|
||||||
|
|
||||||
|
$card = \Sabre\VObject\Component::create('VCARD');
|
||||||
|
$uid = substr(md5(rand().time()), 0, 10);
|
||||||
|
$card->add('UID', $uid);
|
||||||
|
$card->add('FN', 'Max Mustermann');
|
||||||
|
$id = $this->ab->addChild($card);
|
||||||
|
Utils\Properties::updateIndex($id, $card);
|
||||||
|
$this->contactIds[] = $id;
|
||||||
|
|
||||||
|
// Add extra contact
|
||||||
|
$card = \Sabre\VObject\Component::create('VCARD');
|
||||||
|
$uid = substr(md5(rand().time()), 0, 10);
|
||||||
|
$card->add('UID', $uid);
|
||||||
|
$card->add('FN', 'Jan Janssens');
|
||||||
|
$id = $this->ab->addChild($card);
|
||||||
|
Utils\Properties::updateIndex($id, $card);
|
||||||
|
$this->ab->deleteChild($id);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDown() {
|
||||||
|
unset($this->backend);
|
||||||
|
unset($this->ab);
|
||||||
|
Utils\Properties::purgeIndexes($this->contactIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSearch() {
|
||||||
|
$result = $this->provider->search('',array('FN'), array());
|
||||||
|
|
||||||
|
$this->assertTrue(is_array($result));
|
||||||
|
$this->assertEquals(1, count($result));
|
||||||
|
$this->assertEquals('Max Mustermann', $result[0]['FN']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -30,7 +30,7 @@ class BackendTest extends \PHPUnit_Framework_TestCase {
|
|||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var OCA\Contacts\Backend\AbstractBackend
|
* @var \OCA\Contacts\Backend\AbstractBackend
|
||||||
*/
|
*/
|
||||||
protected $backend;
|
protected $backend;
|
||||||
|
|
||||||
|
@ -20,15 +20,15 @@ class ContactTest extends \PHPUnit_Framework_TestCase {
|
|||||||
*/
|
*/
|
||||||
protected $abinfo;
|
protected $abinfo;
|
||||||
/**
|
/**
|
||||||
* @var OCA\Contacts\AddressBook
|
* @var \OCA\Contacts\AddressBook
|
||||||
*/
|
*/
|
||||||
protected $ab;
|
protected $ab;
|
||||||
/**
|
/**
|
||||||
* @var OCA\Contacts\Contact
|
* @var \OCA\Contacts\Contact
|
||||||
*/
|
*/
|
||||||
protected $contact;
|
protected $contact;
|
||||||
/**
|
/**
|
||||||
* @var OCA\Contacts\Backend\AbstractBackend
|
* @var \OCA\Contacts\Backend\AbstractBackend
|
||||||
*/
|
*/
|
||||||
protected $backend;
|
protected $backend;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user