Revision: 18642 http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=18642 Author: johang Date: 2008-07-11 12:39:02 +0000 (Fri, 11 Jul 2008)
Log Message: ----------- Unit tests for ipc in notes module Added Paths: ----------- trunk/notes/test/ trunk/notes/test/all_test.php trunk/notes/test/class.ipc_notes_test.inc.php Added: trunk/notes/test/all_test.php =================================================================== --- trunk/notes/test/all_test.php (rev 0) +++ trunk/notes/test/all_test.php 2008-07-11 12:39:02 UTC (rev 18642) @@ -0,0 +1,55 @@ +<?php + /** + * phpGroupWare (http://phpgroupware.org/) + * Notes module + * + * @author Johan Gunnarsson <[EMAIL PROTECTED]> + * @copyright Copyright (c) 2008 Free Software Foundation, Inc. + * @license GNU General Public License + * @package notes + * @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 notes/ 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'); + + $ipcnotes = CreateObject('notes.ipc_notes'); + + foreach(glob("test/*_test.inc.php") as $n) + { + require_once($n); + } + + $group = new GroupTest('Notes tests'); + $group->addTestCase(new ipc_notes_test($ipcnotes)); + $group->run(new TextReporter()); +?> Added: trunk/notes/test/class.ipc_notes_test.inc.php =================================================================== --- trunk/notes/test/class.ipc_notes_test.inc.php (rev 0) +++ trunk/notes/test/class.ipc_notes_test.inc.php 2008-07-11 12:39:02 UTC (rev 18642) @@ -0,0 +1,179 @@ +<<?php + /** + * phpGroupWare (http://phpgroupware.org/) + * Calendar module + * + * @author Johan Gunnarsson <[EMAIL PROTECTED]> + * @copyright Copyright (c) 2008 Free Software Foundation, Inc. + * @license GNU General Public License 3 or later + * @package calendar + * @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 ipccalendar class in calendar module. + * + * @calendar switch over to phpunit. + */ + class ipc_notes_test extends UnitTestCase + { + private $ipc; + + private $sample_note = 'Hallå-hallå'; + + private $sample_note_array = array( + 'note_access' => 'public', + 'note_category' => NULL, + 'note_description' => 'Hallå-hallå' + ); + + private $sample_item = array(); + + function __construct($ipcnotes) + { + $this->ipc = $ipcnotes; + } + + /** + * Begin each test with erasing the calendar + */ + function setup() + { + foreach($this->ipc->getIdlist() as $d) + { + $this->ipc->removeData($d); + } + } + + function teardown() + { + } + + function test_addData_and_getData() + { + $id = $this->ipc->addData($this->sample_note, 'text/plain'); + + $data = $this->ipc->getData($id, 'text/plain'); + + $this->assertTrue($id); + $this->assertEqual($data, $this->sample_note); + } + + function test_getIdList() + { + $id_list_before = $this->ipc->getIdlist(); + + $a = $this->ipc->addData($this->sample_note, 'text/plain'); + + $id_list_after = $this->ipc->getIdlist(); + + $this->assertEqual($id_list_after, + array_merge($id_list_before, array($a))); + } + + function test_getIdList_with_lastmod() + { + $now = time(); + + $this->assertEqual($this->ipc->getIdlist($now + 10), array()); + $this->assertEqual($this->ipc->getIdlist($now), array()); + $this->assertEqual($this->ipc->getIdlist($now - 10), array()); + + $a = $this->ipc->addData($this->sample_note, 'text/plain'); + + $id_list_plus10 = $this->ipc->getIdlist($now + 10); + $id_list_now = $this->ipc->getIdlist($now); + $id_list_minus10 = $this->ipc->getIdlist($now - 10); + + $this->assertEqual($id_list_plus10, array()); + $this->assertEqual($id_list_now, array()); + $this->assertEqual($id_list_minus10, array($a)); + } + + function test_removeData() + { + $id = $this->ipc->addData($this->sample_note, 'text/plain'); + + $this->assertTrue(is_string( + $this->ipc->getData($id, 'text/plain'))); + + $this->ipc->removeData($id); + + $this->assertFalse($this->ipc->getData($id, 'text/plain')); + } + + function test_replaceData_replace() + { + $id = $this->ipc->addData($this->sample_note, 'text/plain'); + + $this->assertTrue(is_string( + $this->ipc->getData($id, 'text/plain'))); + + $new_item = 'Hello!'; + + $new_id = $this->ipc->replaceData($id, + $new_item, 'text/plain'); + + $this->assertEqual($new_id, $id); + + $data = $this->ipc->getData($id, 'text/plain'); + + $this->assertEqual($new_item, $data); + } + + function test_replaceData_add() + { + $id = 100000; + + $this->assertFalse($this->ipc->existData($id)); + + $new_id = $this->ipc->replaceData($id, $this->sample_note, + 'text/plain'); + + $this->assertTrue($new_id); + $this->assertNotEqual($new_id, $id); + + $this->assertEqual($this->ipc->getData($new_id, 'text/plain'), + $this->sample_note); + } + + function test_existData() + { + $id = $this->ipc->addData($this->sample_note, 'text/plain'); + + $this->assertTrue($this->ipc->existData($id)); + + $this->ipc->removeData($id); + + $this->assertFalse($this->ipc->existData($id)); + } + + function test_convertData_from_plain_1() + { + $converted_data = $this->ipc->convertData( + $this->sample_note, 'text/plain', + 'application/x-phpgw-notes'); + + $this->assertEqual($converted_data['note_description'], + $this->sample_note); + } + + function test_convertData_to_plain_1() + { + $converted_data = $this->ipc->convertData( + $this->sample_note_array, 'application/x-phpgw-notes', + 'text/plain'); + + $this->assertEqual($converted_data, + $this->sample_note_array['note_description']); + } + } +?> _______________________________________________ phpGroupWare-cvs mailing list phpGroupWare-cvs@gnu.org http://lists.gnu.org/mailman/listinfo/phpgroupware-cvs