[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] [18632] * Test for addressbook ipc.
From: |
Johan Gunnarsson |
Subject: |
[Phpgroupware-cvs] [18632] * Test for addressbook ipc. |
Date: |
Wed, 02 Jul 2008 14:24:23 +0000 |
Revision: 18632
http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=18632
Author: johang
Date: 2008-07-02 14:24:21 +0000 (Wed, 02 Jul 2008)
Log Message:
-----------
* Test for addressbook ipc.
* Fixed bug in vcard parsing.
Modified Paths:
--------------
trunk/addressbook/inc/class.ipc_addressbook.inc.php
Added Paths:
-----------
trunk/addressbook/test/
trunk/addressbook/test/all_test.php
trunk/addressbook/test/class.ipc_addressbook_test.inc.php
Modified: trunk/addressbook/inc/class.ipc_addressbook.inc.php
===================================================================
--- trunk/addressbook/inc/class.ipc_addressbook.inc.php 2008-07-01 23:35:59 UTC
(rev 18631)
+++ trunk/addressbook/inc/class.ipc_addressbook.inc.php 2008-07-02 14:24:21 UTC
(rev 18632)
@@ -10,6 +10,7 @@
* @version $Id$
*/
+ phpgw::import_class('phpgwapi.ipc_');
/**
* Fassade of the adressbook application.
@@ -56,16 +57,16 @@
// 1: mapping the mime type to application data
if($type != 'text/x-vcard')
return false;
-
- $data = ereg_replace("\n\n", "\r\n", $data);
- $data_lines = explode("\r\n", $data);
-
+
+ $data_lines = preg_split("/[\r\n]+/", $data);
+
$buffer = array();
$temp_line = '';
-
+
while(list(, $line) = each($data_lines))
{
$line = trim($line);
+
if(substr($line, -1) == '=')
{
// '=' at end-of-line --line to be
continued with next line
@@ -88,6 +89,7 @@
}
$fields = $this->vcard->in($buffer);
+
$fields['owner'] =
$GLOBALS['phpgw_info']['user']['account_id'];
$fields['access'] = 'private';
Added: trunk/addressbook/test/all_test.php
===================================================================
--- trunk/addressbook/test/all_test.php (rev 0)
+++ trunk/addressbook/test/all_test.php 2008-07-02 14:24:21 UTC (rev 18632)
@@ -0,0 +1,55 @@
+<?php
+ /**
+ * phpGroupWare (http://phpgroupware.org/)
+ * Addressbook module
+ *
+ * @author Johan Gunnarsson <address@hidden>
+ * @copyright Copyright (c) 2008 Free Software Foundation, Inc.
+ * @license GNU General Public License
+ * @package addressbook
+ * @version $Id$
+ */
+
+ /*
+ you need simpletest in include_path to run this test case. get
it from
+ their site (http://simpletest.sourceforge.net/en/download.html)
or your
+ nearest debian or debian-like repository (php-simpletest).
+ */
+
+ $_SERVER["HTTP_HOST"] = NULL;
+
+ define("TEST_USER", "demo");
+ define("TEST_PASSWORD", "guest");
+
+ /*
+ run this file from within the addressbook/ directory.
+
+ $ php test/all_tests.php
+ */
+
+ $phpgw_info = array();
+
+ $GLOBALS['phpgw_info']['flags'] = array(
+ 'disable_template_class' => True,
+ 'currentapp' => 'login',
+ 'noheader' => True
+ );
+
+ require_once 'simpletest/reporter.php';
+ require_once("../header.inc.php");
+
+ $GLOBALS['phpgw']->db->query('TRUNCATE phpgw_access_log');
+
+ $GLOBALS['phpgw']->session->create(TEST_USER, md5(TEST_PASSWORD),
'md5');
+
+ $ipcaddressbook = CreateObject('addressbook.ipc_addressbook');
+
+ foreach(glob("test/*_test.inc.php") as $n)
+ {
+ require_once($n);
+ }
+
+ $group = new GroupTest('Addressbook tests');
+ $group->addTestCase(new ipc_addressbook_test($ipcaddressbook));
+ $group->run(new TextReporter());
+?>
Added: trunk/addressbook/test/class.ipc_addressbook_test.inc.php
===================================================================
--- trunk/addressbook/test/class.ipc_addressbook_test.inc.php
(rev 0)
+++ trunk/addressbook/test/class.ipc_addressbook_test.inc.php 2008-07-02
14:24:21 UTC (rev 18632)
@@ -0,0 +1,149 @@
+ <?php
+ /**
+ * phpGroupWare (http://phpgroupware.org/)
+ * Addressbook module
+ *
+ * @author Johan Gunnarsson <address@hidden>
+ * @copyright Copyright (c) 2008 Free Software Foundation, Inc.
+ * @license GNU General Public License 3 or later
+ * @package addressbook
+ * @version $Id$
+ */
+
+ /*
+ you need simpletest in include_path to run this test case. get
it from
+ their site (http://simpletest.sourceforge.net/en/download.html)
or your
+ nearest debian or debian-like repository (php-simpletest).
+ */
+
+ require_once 'simpletest/unit_tester.php';
+
+ /**
+ * Test ipctodo class in addressbook module.
+ *
+ * @todo switch over to phpunit.
+ */
+ class ipc_addressbook_test extends UnitTestCase
+ {
+ private $ipc;
+
+ private $sample_vcard = '
+BEGIN:VCARD
+VERSION:2.1
+N:Gump;Forrest
+FN:Forrest Gump
+ORG:Gump Shrimp Co.
+TITLE:Shrimp Man
+TEL;WORK;VOICE:(111) 555-1212
+TEL;HOME;VOICE:(404) 555-1212
+ADR;WORK:;;100 Waters Edge;Baytown;LA;30314;United States of America
+LABEL;WORK;ENCODING=QUOTED-PRINTABLE:100 Waters Edge=0D=0ABaytown, LA
30314=0D=0AUnited States of America
+ADR;HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America
+LABEL;HOME;ENCODING=QUOTED-PRINTABLE:42 Plantation St.=0D=0ABaytown, LA
30314=0D=0AUnited States of America
+EMAIL;PREF;INTERNET:address@hidden
+REV:20080424T195243Z
+END:VCARD';
+
+ private $sample_vcard_changed = '
+BEGIN:VCARD
+VERSION:2.1
+N:Gump;Forrest
+FN:Bubba
+ORG:Gump Shrimp Co.
+TITLE:Shrimp Man
+TEL;WORK;VOICE:(111) 555-1212
+TEL;HOME;VOICE:(404) 555-1212
+ADR;WORK:;;100 Waters Edge;Baytown;LA;30314;United States of America
+LABEL;WORK;ENCODING=QUOTED-PRINTABLE:100 Waters Edge=0D=0ABaytown, LA
30314=0D=0AUnited States of America
+ADR;HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America
+LABEL;HOME;ENCODING=QUOTED-PRINTABLE:42 Plantation St.=0D=0ABaytown, LA
30314=0D=0AUnited States of America
+EMAIL;PREF;INTERNET:address@hidden
+REV:20080424T195243Z
+END:VCARD';
+
+ private $sample_item = array
+ (
+ );
+
+ function __construct($ipcaddressbook)
+ {
+ $this->ipc = $ipcaddressbook;
+ }
+
+ function setup()
+ {
+ }
+
+ function teardown()
+ {
+ }
+
+ function test_addData_and_getData()
+ {
+ $id = $this->ipc->addData($this->sample_vcard,
'text/x-vcard');
+ $this->assertFalse($id === FALSE);
+
+ $data = $this->ipc->getData($id, 'text/x-vcard');
+ $this->assertTrue(is_string($data));
+ }
+
+ function test_getIdList()
+ {
+ $id_list_before = $this->ipc->getIdlist();
+
+ $a = $this->ipc->addData($this->sample_vcard,
'text/x-vcard');
+ $b = $this->ipc->addData($this->sample_vcard,
'text/x-vcard');
+ $c = $this->ipc->addData($this->sample_vcard,
'text/x-vcard');
+
+ $id_list_after = $this->ipc->getIdlist();
+
+ $this->assertEqual($id_list_after,
+ array_merge($id_list_before, array($a, $b,
$c)));
+ }
+
+ function test_removeData()
+ {
+ $id = $this->ipc->addData($this->sample_vcard,
'text/x-vcard');
+
+ $this->assertTrue(is_string($this->ipc->getData($id,
+ 'text/x-vcard')));
+
+ $this->ipc->removeData($id);
+
+ $this->assertFalse($this->ipc->getData($id,
'text/x-vcard'));
+ }
+
+ /**
+ * @todo not working properly.
+ */
+ function test_replaceData()
+ {
+ $id = $this->ipc->addData($this->sample_vcard,
'text/x-vcard');
+
+ $this->assertTrue(is_string($this->ipc->getData($id,
+ 'text/x-vcard')));
+
+ // @todo test when replacing item that not already
exists
+
+ $this->assertTrue($this->ipc->replaceData($id,
+ $this->sample_vcard_changed, 'text/x-vcard'));
+
+ $data = $this->ipc->getData($id, 'text/x-vcard');
+
+ $this->assertTrue(strpos($data, 'Bubba'));
+
+ // @todo test more properties
+ }
+
+ function test_existData()
+ {
+ $id = $this->ipc->addData($this->sample_vcard,
'text/x-vcard');
+
+ $this->assertTrue($this->ipc->existData($id));
+
+ $this->ipc->removeData($id);
+
+ $this->assertFalse($this->ipc->existData($id));
+ }
+ }
+?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] [18632] * Test for addressbook ipc.,
Johan Gunnarsson <=