From 504418dc009500574c664b75ccdb0796b157265b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 5 Aug 2014 22:20:50 +0200 Subject: [PATCH 1/9] adding first unit test for search of address book provider --- tests/lib/addressbook_test.php | 4 +- tests/lib/addressbookprovider_test.php | 74 ++++++++++++++++++++++++++ tests/lib/backend/backend_test.php | 2 +- tests/lib/contact_test.php | 8 +-- 4 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 tests/lib/addressbookprovider_test.php diff --git a/tests/lib/addressbook_test.php b/tests/lib/addressbook_test.php index 68acbca9..062fca82 100644 --- a/tests/lib/addressbook_test.php +++ b/tests/lib/addressbook_test.php @@ -19,11 +19,11 @@ class AddressBookTest extends \PHPUnit_Framework_TestCase { */ protected $abinfo; /** - * @var OCA\Contacts\AddressBook + * @var \OCA\Contacts\Addressbook */ protected $ab; /** - * @var OCA\Contacts\Backend\AbstractBackend + * @var \OCA\Contacts\Backend\AbstractBackend */ protected $backend; diff --git a/tests/lib/addressbookprovider_test.php b/tests/lib/addressbookprovider_test.php new file mode 100644 index 00000000..a5d1bc43 --- /dev/null +++ b/tests/lib/addressbookprovider_test.php @@ -0,0 +1,74 @@ +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; + + } + + 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']); + } + + +} diff --git a/tests/lib/backend/backend_test.php b/tests/lib/backend/backend_test.php index 399c499e..155676fa 100644 --- a/tests/lib/backend/backend_test.php +++ b/tests/lib/backend/backend_test.php @@ -30,7 +30,7 @@ class BackendTest extends \PHPUnit_Framework_TestCase { ); /** - * @var OCA\Contacts\Backend\AbstractBackend + * @var \OCA\Contacts\Backend\AbstractBackend */ protected $backend; diff --git a/tests/lib/contact_test.php b/tests/lib/contact_test.php index 9b45ba25..3665e96b 100644 --- a/tests/lib/contact_test.php +++ b/tests/lib/contact_test.php @@ -20,15 +20,15 @@ class ContactTest extends \PHPUnit_Framework_TestCase { */ protected $abinfo; /** - * @var OCA\Contacts\AddressBook + * @var \OCA\Contacts\AddressBook */ protected $ab; /** - * @var OCA\Contacts\Contact + * @var \OCA\Contacts\Contact */ protected $contact; /** - * @var OCA\Contacts\Backend\AbstractBackend + * @var \OCA\Contacts\Backend\AbstractBackend */ protected $backend; @@ -165,4 +165,4 @@ class ContactTest extends \PHPUnit_Framework_TestCase { } -} \ No newline at end of file +} From eaff05732423a7c4d9443962a50553aa0382f041 Mon Sep 17 00:00:00 2001 From: LEDfan Date: Wed, 3 Sep 2014 15:15:28 +0200 Subject: [PATCH 2/9] Add MySQL to travis run list to make sure unit tests are working --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 51d6cd72..25972419 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,7 @@ branches: env: - DB=sqlite - -# - DB=mysql + - DB=mysql # - DB=pgsql before_install: From be0bdd21fe9367691f5129ddd393a670970c16ca Mon Sep 17 00:00:00 2001 From: LEDfan Date: Wed, 3 Sep 2014 15:25:54 +0200 Subject: [PATCH 3/9] Should fix not installed error --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 25972419..03023616 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,8 +14,8 @@ env: # - DB=pgsql before_install: - - ./tests/install_dependencies.sh - - tests/setup_owncloud.sh + - wget https://raw.githubusercontent.com/owncloud/administration/master/travis-ci/before_install.sh + - bash ./before_install.sh chat master $D # - sudo add-apt-repository -y ppa:chris-lea/node.js # - sudo apt-get update From 0de65d29d0dd1912a6cacf43d4df8305f3281b06 Mon Sep 17 00:00:00 2001 From: LEDfan Date: Wed, 3 Sep 2014 15:27:29 +0200 Subject: [PATCH 4/9] Fix typos --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 03023616..80bb30e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ env: before_install: - wget https://raw.githubusercontent.com/owncloud/administration/master/travis-ci/before_install.sh - - bash ./before_install.sh chat master $D + - bash ./before_install.sh contacts master $DB # - sudo add-apt-repository -y ppa:chris-lea/node.js # - sudo apt-get update From b46843ea5078c9a5a0dc93fd0463cfe3a1de960c Mon Sep 17 00:00:00 2001 From: LEDfan Date: Sat, 6 Sep 2014 14:42:10 +0200 Subject: [PATCH 5/9] Also test deleting of child --- tests/bootstrap.php | 2 +- tests/lib/addressbookprovider_test.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 8d310d28..ced483cd 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -7,7 +7,7 @@ if(!defined('PHPUNIT_RUN')) { define('PHPUNIT_RUN', 1); } -require_once __DIR__.'/../../core/lib/base.php'; +require_once __DIR__.'/../../../lib/base.php'; if(!class_exists('PHPUnit_Framework_TestCase')) { require_once('PHPUnit/Autoload.php'); diff --git a/tests/lib/addressbookprovider_test.php b/tests/lib/addressbookprovider_test.php index a5d1bc43..a7392301 100644 --- a/tests/lib/addressbookprovider_test.php +++ b/tests/lib/addressbookprovider_test.php @@ -52,6 +52,15 @@ class AddressBookProviderTest extends \PHPUnit_Framework_TestCase { $id = $this->ab->addChild($card); Utils\Properties::updateIndex($id, $card); + // 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); + $this->contactIds[] = $id; } From 40c3594c22da8c52972534e9e505c1489fdb78fe Mon Sep 17 00:00:00 2001 From: LEDfan Date: Sat, 6 Sep 2014 14:44:55 +0200 Subject: [PATCH 6/9] Fix mistake --- tests/bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index ced483cd..8d310d28 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -7,7 +7,7 @@ if(!defined('PHPUNIT_RUN')) { define('PHPUNIT_RUN', 1); } -require_once __DIR__.'/../../../lib/base.php'; +require_once __DIR__.'/../../core/lib/base.php'; if(!class_exists('PHPUnit_Framework_TestCase')) { require_once('PHPUnit/Autoload.php'); From 79bc4679de94421803494b1dc54c2a548263de93 Mon Sep 17 00:00:00 2001 From: LEDfan Date: Sat, 6 Sep 2014 17:27:13 +0200 Subject: [PATCH 7/9] Connect pre_deleteContact when unit tests are run --- tests/bootstrap.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 8d310d28..952a0fb2 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -6,8 +6,7 @@ $RUNTIME_NOAPPS = true; if(!defined('PHPUNIT_RUN')) { define('PHPUNIT_RUN', 1); } - -require_once __DIR__.'/../../core/lib/base.php'; +require_once __DIR__.'/../../../lib/base.php'; if(!class_exists('PHPUnit_Framework_TestCase')) { require_once('PHPUnit/Autoload.php'); @@ -17,3 +16,5 @@ if(!class_exists('PHPUnit_Framework_TestCase')) { OC_Hook::clear(); OC_Log::$enabled = true; +\OCP\Util::connectHook('OCA\Contacts', 'pre_deleteContact', '\OCA\Contacts\Hooks', 'contactDeletion'); + From 5e47fe9f6532fab62094b4552407e70f5a593eae Mon Sep 17 00:00:00 2001 From: LEDfan Date: Sat, 6 Sep 2014 17:31:23 +0200 Subject: [PATCH 8/9] only purge not deleted contacts --- tests/lib/addressbookprovider_test.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/lib/addressbookprovider_test.php b/tests/lib/addressbookprovider_test.php index a7392301..102a8013 100644 --- a/tests/lib/addressbookprovider_test.php +++ b/tests/lib/addressbookprovider_test.php @@ -51,6 +51,7 @@ class AddressBookProviderTest extends \PHPUnit_Framework_TestCase { $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'); @@ -61,13 +62,14 @@ class AddressBookProviderTest extends \PHPUnit_Framework_TestCase { Utils\Properties::updateIndex($id, $card); $this->ab->deleteChild($id); - $this->contactIds[] = $id; } public function tearDown() { unset($this->backend); unset($this->ab); +// var_dump($this->contactIds); +// die(); Utils\Properties::purgeIndexes($this->contactIds); } From d0f5e761b84a39cb6c73e94cdb22136cc0c0273c Mon Sep 17 00:00:00 2001 From: LEDfan Date: Sat, 6 Sep 2014 17:32:42 +0200 Subject: [PATCH 9/9] Undo wrong change --- tests/bootstrap.php | 2 +- tests/lib/addressbookprovider_test.php | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 952a0fb2..65114cff 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -6,7 +6,7 @@ $RUNTIME_NOAPPS = true; if(!defined('PHPUNIT_RUN')) { define('PHPUNIT_RUN', 1); } -require_once __DIR__.'/../../../lib/base.php'; +require_once __DIR__.'/../../core/lib/base.php'; if(!class_exists('PHPUnit_Framework_TestCase')) { require_once('PHPUnit/Autoload.php'); diff --git a/tests/lib/addressbookprovider_test.php b/tests/lib/addressbookprovider_test.php index 102a8013..b6959318 100644 --- a/tests/lib/addressbookprovider_test.php +++ b/tests/lib/addressbookprovider_test.php @@ -68,8 +68,6 @@ class AddressBookProviderTest extends \PHPUnit_Framework_TestCase { public function tearDown() { unset($this->backend); unset($this->ab); -// var_dump($this->contactIds); -// die(); Utils\Properties::purgeIndexes($this->contactIds); }