diff --git a/bin/upgrade/pear-upgrade.bat b/bin/upgrade/pear-upgrade.bat deleted file mode 100644 index bb9fa80..0000000 --- a/bin/upgrade/pear-upgrade.bat +++ /dev/null @@ -1,27 +0,0 @@ - -; TEST ALL PEAR LIBRARIES BEFORE UPGRADING INTO RELEASE - -PATH=%PATH%;c:\php5\PEAR - -pear channel-update pear.php.net -pear config-set php_dir "C:\kt\kt.trunk\thirdparty\pear" - -pear config-set preferred_state stable - -pear upgrade --alldeps PEAR -pear upgrade --alldeps Cache_Lite -pear upgrade --alldeps Config -pear upgrade --alldeps DB -pear upgrade --alldeps File - -;pear upgrade --alldeps MDB2#mysql - -pear upgrade --alldeps Log -pear upgrade --alldeps PHP_Compat - -pear config-set preferred_state beta -pear upgrade --alldeps File_Gettext -pear upgrade --alldeps Net_LDAP -pear upgrade --alldeps SOAP -pear config-set preferred_state stable - diff --git a/bin/upgrade/pear-upgrade.sh b/bin/upgrade/pear-upgrade.sh deleted file mode 100755 index cbd0323..0000000 --- a/bin/upgrade/pear-upgrade.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/bash - -# -# This script will upgrade all the pear components specific to knowledgetree -# - -#KTDIR="/var/www/knowledgetree" -KTDIR="$1"; -TMPDIR="$KTDIR/var/pear" - -if [ "$KTDIR" == "" ]; then - echo "Usage: $0 path/to/knowledgetree/directory"; - echo "e.g. $0 /var/www/knowledgetree"; - exit; -fi - -if [ ! -x "$TMPDIR" ]; then - mkdir -p "$TMPDIR" -fi - -if [ ! -x "$(which pear)" ]; then - echo "pear is not installed. please install pear before using this script."; - exit; -fi - -# Installing latest pear packages into tmp directory -pear config-set php_dir "$TMPDIR" -pear channel-update pear.php.net -pear config-set preferred_state stable -pear install --alldeps PEAR -pear install --alldeps Cache_Lite -pear install --alldeps Config -pear install --alldeps DB -pear install --alldeps File -pear install --alldeps MDB2#mysql -pear install --alldeps Log -pear install --alldeps PHP_Compat -pear install --alldeps Services_JSON -pear install --alldeps MIME_Type -pear config-set preferred_state beta -pear install --alldeps File_Gettext -pear install --alldeps Net_LDAP -pear install --alldeps SOAP -pear config-set preferred_state stable - -# Backing up the current pear directory -tar -czvf "$TMPDIR/pear_backup_$(date +%Y%m%d).tgz" "$KTDIR/thirdparty/pear" - -# -# The following section was created via an ls in the current knowledgetree -# pear directory for version 3.7.0.3 -# -# It contains the accurate/compressed list of pear packages known to be currently -# needed by knowledgetree. If any new package is implemented it should be added -# to this list to stay in the upgrade path. -# - -cp -frv "$TMPDIR/Config.php" "$KTDIR/thirdparty/pear/" -cp -frv "$TMPDIR/Console" "$KTDIR/thirdparty/pear/" -cp -frv "$TMPDIR/DB" "$KTDIR/thirdparty/pear/" -cp -frv "$TMPDIR/DB.php" "$KTDIR/thirdparty/pear/" -cp -frv "$TMPDIR/File" "$KTDIR/thirdparty/pear/" -cp -frv "$TMPDIR/GraphViz.php" "$KTDIR/thirdparty/pear/" -cp -frv "$TMPDIR/HTTP" "$KTDIR/thirdparty/pear/" -cp -frv "$TMPDIR/HTTP.php" "$KTDIR/thirdparty/pear/" -cp -frv "$TMPDIR/JSON.php" "$KTDIR/thirdparty/pear/" -cp -frv "$TMPDIR/Log" "$KTDIR/thirdparty/pear/" -cp -frv "$TMPDIR/Log.php" "$KTDIR/thirdparty/pear/" -cp -frv "$TMPDIR/MIME" "$KTDIR/thirdparty/pear/" -cp -frv "$TMPDIR/Net" "$KTDIR/thirdparty/pear/" -cp -frv "$TMPDIR/PEAR.php" "$KTDIR/thirdparty/pear/" -cp -frv "$TMPDIR/PHP" "$KTDIR/thirdparty/pear/" -cp -frv "$TMPDIR/SOAP" "$KTDIR/thirdparty/pear/" -cp -frv "$TMPDIR/System.php" "$KTDIR/thirdparty/pear/" diff --git a/ktapi/KTAPIFolder.inc.php b/ktapi/KTAPIFolder.inc.php index 105b598..74b9d5d 100755 --- a/ktapi/KTAPIFolder.inc.php +++ b/ktapi/KTAPIFolder.inc.php @@ -291,7 +291,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @param int $folderid * @return KTAPI_Folder */ - function _get_folder_by_name($ktapi, $foldername, $folderid) + function _get_folder_by_name($ktapi, $foldername, $parentId) { $foldername=trim($foldername); if (empty($foldername)) @@ -310,8 +310,8 @@ class KTAPI_Folder extends KTAPI_FolderItem $foldername = KTUtil::replaceInvalidCharacters($foldername); $foldername = sanitizeForSQL($foldername); $sql = "SELECT id FROM folders WHERE - (name='$foldername' and parent_id=$folderid) OR - (name='$foldername' and parent_id is null and $folderid=1)"; + (name='$foldername' and parent_id=$parentId) OR + (name='$foldername' and parent_id is null and $parentId=1)"; $row = DBUtil::getOneResult($sql); if (is_null($row) || PEAR::isError($row)) { @@ -377,7 +377,8 @@ class KTAPI_Folder extends KTAPI_FolderItem if (!empty($foldername) && ($foldername != '.')) { - $ktapi_folder = $this->get_folder_by_name($foldername); + // TODO confirm that this addition of the parent folder id as second parameter is correct and necessary + $ktapi_folder = $this->get_folder_by_name($foldername, $this->folderid); } $currentFolderName = $this->get_folder_name(); @@ -391,7 +392,8 @@ class KTAPI_Folder extends KTAPI_FolderItem else { $foldername = substr($foldername, strlen($currentFolderName)+1); - $ktapi_folder = $this->get_folder_by_name($foldername); + // TODO confirm that this addition of the parent folder id as second parameter is correct and necessary + $ktapi_folder = $this->get_folder_by_name($foldername, $this->folderid); } } diff --git a/ktapi/ktapi.inc.php b/ktapi/ktapi.inc.php index 6619201..09d2a4a 100644 --- a/ktapi/ktapi.inc.php +++ b/ktapi/ktapi.inc.php @@ -842,11 +842,12 @@ class KTAPI * @author KnowledgeTree Team * @access public * @param string $foldername The folder name + * @param int $parent_id The folder in which to search for the requested child folder * @return object $folder The KTAPI_Folder object */ - public function &get_folder_by_name($foldername, $parentId = 1) + public function &get_folder_by_name($foldername, $parent_id = 1) { - $folder = KTAPI_Folder::_get_folder_by_name($this, $foldername, $parentId); + $folder = KTAPI_Folder::_get_folder_by_name($this, $foldername, $parent_id); return $folder; } @@ -2027,14 +2028,14 @@ class KTAPI function get_folder_shortcuts($folder_id) { $folder = $this->get_folder_by_id($folder_id); - if(PEAR::isError($folder)){ + if(PEAR::isError($folder)) { $response['status_code'] = 1; $response['message']= $folder->getMessage(); return $response; } $shortcuts = $folder->get_shortcuts(); - if(PEAR::isError($shortcuts)){ + if(PEAR::isError($shortcuts)) { $response['status_code'] = 1; $response['message']= $shortcuts->getMessage(); return $response; @@ -2054,10 +2055,10 @@ class KTAPI * @param string $folder_name The name of the folder * @return array Response 'results' contains kt_folder_detail | 'message' contains error message on failure */ - function get_folder_detail_by_name($folder_name) + function get_folder_detail_by_name($folder_name, $parent_id = 1) { - $folder = &$this->get_folder_by_name($folder_name); - if(PEAR::isError($folder)){ + $folder = &$this->get_folder_by_name($folder_name, $parent_id); + if(PEAR::isError($folder)) { $response['status_code'] = 1; $response['message']= $folder->getMessage(); return $response; @@ -2343,7 +2344,7 @@ class KTAPI $sourceName = $src_folder->get_folder_name(); $targetPath = $tgt_folder->get_full_path(); - $response['results'] = $this->get_folder_detail_by_name($targetPath . '/' . $sourceName); + $response['results'] = $this->get_folder_detail_by_name($targetPath . '/' . $sourceName, $source_id); return $response; } diff --git a/ktwebservice/webservice.php b/ktwebservice/webservice.php index 8e8f3c9..f03b85c 100644 --- a/ktwebservice/webservice.php +++ b/ktwebservice/webservice.php @@ -769,14 +769,20 @@ class KTWebService // get_folder_detail_by_name $this->__dispatch_map['get_folder_detail_by_name'] = - array('in' => array('session_id' => 'string', 'folder_name' => 'string' ), + array('in' => array('session_id' => 'string', 'folder_name' => 'string', 'parent_id' => 'int' ), 'out' => array('return' => "{urn:$this->namespace}kt_folder_detail"), ); + /* If this is now the same as version 2 for this function, we don't need this. + * if ($this->version >=3) { + // was $this->__dispatch_map['get_folder_detail_by_name']['in'] = array('session_id' => 'string', 'folder_id' => 'int', 'create'=>'boolean' ); + // now + $this->__dispatch_map['get_folder_detail_by_name']['in'] = array('session_id' => 'string', 'folder_id' => 'int', 'parent_id'=>'int' ); } + */ // get_folder_contents $this->__dispatch_map['get_folder_contents'] = @@ -1507,22 +1513,23 @@ class KTWebService * * @param string $session_id * @param string $folder_name + * @param integer $parent_id The parent folder in which to look for the named folder * @return kt_folder_detail. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_FOLDER, or KTWS_SUCCESS. */ - function get_folder_detail_by_name($session_id, $folder_name) + function get_folder_detail_by_name($session_id, $folder_name, $parent_id = 1) { - $this->debug("get_folder_detail_by_name('$session_id','$folder_name')"); + $this->debug("get_folder_detail_by_name('$session_id','$folder_name','$parent_id')"); $kt = &$this->get_ktapi($session_id); if (is_array($kt)) { return new SOAP_Value('return',"{urn:$this->namespace}kt_folder_detail", $kt); } - $folder = &$kt->get_folder_by_name($folder_name); + $folder = &$kt->get_folder_by_name($folder_name, $parent_id); if (PEAR::isError($folder)) { $response = KTWebService::_status(KTWS_ERR_INVALID_FOLDER,$folder); - $this->debug("get_folder_detail_by_name - cannot get folder $folder_name - " . $folder->getMessage(), $session_id); + $this->debug("get_folder_detail_by_name - cannot get folder $folder_name (looking in folder $parent_id) - " . $folder->getMessage(), $session_id); return new SOAP_Value('return',"{urn:$this->namespace}kt_folder_detail", $response); } @@ -1883,11 +1890,10 @@ class KTWebService if ($this->version >=2) { - $sourceName = $src_folder->get_folder_name(); $targetPath = $tgt_folder->get_full_path(); - $response = $this->get_folder_detail_by_name($session_id, $targetPath . '/' . $sourceName); + $response = $this->get_folder_detail_by_name($session_id, $targetPath . '/' . $sourceName, $source_id); return $response; } diff --git a/plugins/ktcore/KTBulkActions.php b/plugins/ktcore/KTBulkActions.php index 79a1682..13ed4f3 100644 --- a/plugins/ktcore/KTBulkActions.php +++ b/plugins/ktcore/KTBulkActions.php @@ -90,13 +90,10 @@ class KTBulkDeleteAction extends KTBulkAction { } // If all documents at the current level may be deleted, we can continue - // Get any existing subfolders - $sWhereClause = "parent_folder_ids = '{$sFolderId}' OR - parent_folder_ids LIKE '{$sFolderId},%' OR - parent_folder_ids LIKE '%,{$sFolderId},%' OR - parent_folder_ids LIKE '%,{$sFolderId}'"; + // Get any existing subfolders - but ONLY on the current level, or we will be checking subfolders more than once! + $sWhereClause = "parent_id = '{$sFolderId}'"; $aChildFolders = $this->oFolder->getList($sWhereClause); - + // Loop through subfolders and check each in the same way as the parent if(!empty($aChildFolders)){ foreach($aChildFolders as $oChild){ diff --git a/plugins/ktcore/admin/manageBranding.php b/plugins/ktcore/admin/manageBranding.php index 1d8798d..75ba5b7 100755 --- a/plugins/ktcore/admin/manageBranding.php +++ b/plugins/ktcore/admin/manageBranding.php @@ -47,7 +47,6 @@ require_once(KT_LIB_DIR . "/validation/dispatchervalidation.inc.php"); require_once(KT_LIB_DIR . "/metadata/fieldsetregistry.inc.php"); require_once(KT_LIB_DIR . "/validation/validatorfactory.inc.php"); - class ManageBrandDispatcher extends KTAdminDispatcher { private $maxLogoWidth = 313; @@ -61,7 +60,6 @@ class ManageBrandDispatcher extends KTAdminDispatcher { } function do_main() { - $oForms[] = $this->getLogoDetailsForm(); $oForms[] = $this->getUploadLogoForm(); @@ -98,10 +96,11 @@ class ManageBrandDispatcher extends KTAdminDispatcher { 'encoding' => 'multipart/form-data', 'context' => &$this, 'extraargs' => $this->meldPersistQuery("","",true), - 'description' => _kt('You can set the branding details.') + 'description' => _kt('You can set the branding details.') )); $oWF =& KTWidgetFactory::getSingleton(); + $oVF =& KTValidatorFactory::getSingleton(); $widgets = array(); $validators = array(); @@ -126,7 +125,14 @@ class ManageBrandDispatcher extends KTAdminDispatcher { 'name' => 'logo_url', 'id' => 'file', 'value' => $logoUrl, - 'description' => _kt("This is the website address you will be redirected to after clicking the logo"), + 'description' => _kt("This is the website address you will be redirected to after clicking the logo. The url should include the protocol e.g. http://www.knowledgetree.com . If no protocol is given the url is treated as a relative link."), + )); + + + // Adding the url widget + $validators[] = $oVF->get('ktcore.widgets.string', array( + 'test' => 'logo_url', + 'output' => 'logo_url', )); $oForm->setWidgets($widgets); @@ -430,9 +436,6 @@ class ManageBrandDispatcher extends KTAdminDispatcher { return $oForm; } - - - /* * Action responsible for setting the logo details @@ -446,6 +449,12 @@ class ManageBrandDispatcher extends KTAdminDispatcher { $logoUrl = $_REQUEST['data']['logo_url']; $logoTitle = $_REQUEST['data']['logo_title']; + $aOptions = array('redirect_to' => 'main'); + + if ($logoTitle != '') { + $this->oValidator->validateIllegalCharacters($logoTitle, $aOptions); + } + if ($config->set('ui/companyLogoUrl', $logoUrl) && $config->set('ui/companyLogoTitle', $logoTitle)) { $this->successRedirectTo('main', _kt('Logo fields have been successfully updated.')); } else { @@ -454,8 +463,6 @@ class ManageBrandDispatcher extends KTAdminDispatcher { } - - /* * Action responsible for uploading the logo * @@ -597,7 +604,6 @@ class ManageBrandDispatcher extends KTAdminDispatcher { } - /** * Returns the MIME of the filename, deducted from its extension * If the extension is unknown, returns "image/jpeg" @@ -674,7 +680,6 @@ class ManageBrandDispatcher extends KTAdminDispatcher { return FALSE; } - /* * This method uses the GD library to scale an image. diff --git a/sql/mysql/install/data.sql b/sql/mysql/install/data.sql index 221b4c1..210b26c 100755 --- a/sql/mysql/install/data.sql +++ b/sql/mysql/install/data.sql @@ -1781,7 +1781,8 @@ INSERT INTO `upgrades` VALUES (235,'sql*3.7.0.3*0*3.7.0.3/clienttools_config.sql','Database upgrade to version 3.7.0.3: Clienttools Config','2009-12-10 00:00:00',1,'upgrade*3.7.0.3*99*upgrade3.7.0.3'), (236,'sql*3.7.0.3*0*3.7.0.3/uploaded_files.sql','Database upgrade to version 3.7.0.3: Uploaded Files','2009-12-10 00:00:00',1,'upgrade*3.7.0.3*99*upgrade3.7.0.3'), (237,'sql*3.7.0.3*0*3.7.0.3/active_sessions_ip.sql','Database upgrade to version 3.7.0.3: Active Sessions Ip','2009-12-10 00:00:00',1,'upgrade*3.7.0.3*99*upgrade3.7.0.3'), -(238,'upgrade*3.7.0.3*99*upgrade3.7.0.3','Upgrade from version 3.7.0.2 to 3.7.0.3','2009-12-14 00:00:00',1,'upgrade*3.7.0.3*99*upgrade3.7.0.3'); +(238,'sql*3.7.0.3*0*3.7.0.3/download_queue_zip.sql','Database upgrade to version 3.7.0.3: Download Queue Zip','2009-12-10 00:00:00',1,'upgrade*3.7.0.3*99*upgrade3.7.0.3'), +(239,'upgrade*3.7.0.3*99*upgrade3.7.0.3','Upgrade from version 3.7.0.2 to 3.7.0.3','2009-12-14 00:00:00',1,'upgrade*3.7.0.3*99*upgrade3.7.0.3'); /*!40000 ALTER TABLE `upgrades` ENABLE KEYS */; UNLOCK TABLES; diff --git a/tests/api/testApi.php b/tests/api/testApi.php index 9f4c449..6fabc03 100644 --- a/tests/api/testApi.php +++ b/tests/api/testApi.php @@ -295,6 +295,7 @@ class APITestCase extends KTUnitTestCase { * This method tests the retrieval of a folder by name * */ + /* replaced by the new function below public function testGetFolderByName() { $folder = $this->ktapi->get_folder_by_name('Root Folder'); @@ -303,6 +304,7 @@ class APITestCase extends KTUnitTestCase { $this->assertIsA($folder, 'KTAPI_Folder'); $this->assertNoErrors(); } + */ /** * This method tests the retrieval of a document by it's id @@ -607,6 +609,181 @@ class APITestCase extends KTUnitTestCase { $detail2 = $this->ktapi->get_folder_detail($folder_id); $this->assertNotEqual($detail2['status_code'], 0); } + + /** + * Tests finding of a folder or folder detail by name + * + * Runs the following sub-tests: + * + * . Root folder Folder by Name (root folder test) + * . Folder Detail by Name in root folder (no duplicate names) + * . Folder Detail by name in subfolder of root folder (no duplicate names) + * . Folder by Name in subfolder of root folder (no duplicate names) + * . Folder by Name in root folder (duplicate names) + * . Folder Detail by name in subfolder of root folder (duplicate names) + * . Folder by name in subfolder of root folder (duplicate names) + */ + public function testGetFolderByName() + { + // set up + $root_folder_id = array(); + $sub_folder_id = array(); + $folders[0][1] = 'Root Folder'; + + // Create a sub folder in the root folder + $parentId = 1; + $folderName = 'Test api sub-folder ONE'; + $result1 = $this->ktapi->create_folder($parentId, $folderName, KT_TEST_USER, KT_TEST_PASS, 'Testing API'); + $root_folder_id[] = $result1['results']['id']; + $folders[$parentId][$result1['results']['id']] = $folderName; + $this->assertEqual($result1['status_code'], 0); + + // Create a second sub folder in the root folder + $parentId = 1; + $folderName = 'Test api sub-folder TWO'; + $result1 = $this->ktapi->create_folder($parentId, $folderName, KT_TEST_USER, KT_TEST_PASS, 'Testing API'); + $root_folder_id[] = $result1['results']['id']; + $folders[$parentId][$result1['results']['id']] = $folderName; + $this->assertEqual($result1['status_code'], 0); + + // Create a sub folder in the first sub folder + $parentId = $root_folder_id[0]; + $folderName = 'Test api sub-folder THREE'; + $result2 = $this->ktapi->create_folder($parentId, $folderName, KT_TEST_USER, KT_TEST_PASS, 'Testing API'); + $sub_folder_id[0][] = $result2['results']['id']; + $folders[$parentId][$result2['results']['id']] = $folderName; + $this->assertEqual($result2['status_code'], 0); + + // Create a sub folder within the first sub folder which shares a name with one of the root sub folders + $parentId = $sub_folder_id[0][0]; + $folderName = 'Test api sub-folder TWO'; + $result2 = $this->ktapi->create_folder($parentId, $folderName, KT_TEST_USER, KT_TEST_PASS, 'Testing API'); + $sub_folder_id[0][] = $result2['results']['id']; + $folders[$parentId][$result2['results']['id']] = $folderName; + $this->assertEqual($result2['status_code'], 0); + + // Create a second sub folder in the first sub folder + $parentId = $root_folder_id[0]; + $folderName = 'Test api sub-folder FOUR'; + $result2 = $this->ktapi->create_folder($parentId, $folderName, KT_TEST_USER, KT_TEST_PASS, 'Testing API'); + $sub_folder_id[0][] = $result2['results']['id']; + $folders[$parentId][$result2['results']['id']] = $folderName; + $this->assertEqual($result2['status_code'], 0); + + // Create a sub folder within the second sub folder + $parentId = $root_folder_id[1]; + $folderName = 'Test api sub-folder FIVE'; + $result2 = $this->ktapi->create_folder($parentId, $folderName, KT_TEST_USER, KT_TEST_PASS, 'Testing API'); + $sub_folder_id[1][] = $result2['results']['id']; + $folders[$parentId][$result2['results']['id']] = $folderName; + $this->assertEqual($result2['status_code'], 0); + + // Create a sub folder within the second sub folder which shares a name with a sub folder in the first sub folder + $parentId = $sub_folder_id[1][0]; + $folderName = 'Test api sub-folder THREE'; + $result2 = $this->ktapi->create_folder($parentId, $folderName, KT_TEST_USER, KT_TEST_PASS, 'Testing API'); + $sub_folder_id[1][] = $result2['results']['id']; + $folders[$parentId][$result2['results']['id']] = $folderName; + $this->assertEqual($result2['status_code'], 0); + + // NOTE default parent is 1, so does not need to be declared when searching the root folder, but we use it elsewhere + + // Fetching of root folder - this used to be in the other test + $parentId = 0; + $folderName = 'Root Folder'; + // no parent required + $folder = $this->ktapi->get_folder_by_name($folderName); + $this->assertNotNull($folder); + $this->assertIsA($folder, 'KTAPI_Folder'); + $this->assertNoErrors(); + // confirm folder id matches expected + if (is_a($folder, 'KTAPI_Folder')) { + $this->assertEqual($folders[$parentId][$folder->get_folderid()], $folderName); + } + + // Folder Detail by Name in root folder (no duplicate names) + $parentId = 1; + $folderName = 'Test api sub-folder ONE'; + // no parent required + $response = $this->ktapi->get_folder_detail_by_name($folderName); + $this->assertNotNull($response['results']); + $this->assertNoErrors(); + // confirm folder id matches expected + if (!empty($response)) { + $this->assertEqual($folders[$parentId][$response['results']['id']], $folderName); + } + + // Folder Detail by Name in sub folder of root folder (no duplicate names) + $parentId = $root_folder_id[0]; + $folderName = 'Test api sub-folder FOUR'; + // no parent required + $response = $this->ktapi->get_folder_detail_by_name($folderName, $parentId); + $this->assertNotNull($response['results']); + $this->assertNoErrors(); + // confirm folder id matches expected + if (!empty($response)) { + $this->assertEqual($folders[$parentId][$response['results']['id']], $folderName); + } + + // Folder by Name in subfolder of root folder (no duplicate names) + $parentId = $root_folder_id[0]; + $folderName = 'Test api sub-folder FOUR'; + $folder = $this->ktapi->get_folder_by_name($folderName, $parentId); + $this->assertNotNull($folder); + $this->assertIsA($folder, 'KTAPI_Folder'); + $this->assertNoErrors(); + // confirm folder id matches expected + if (is_a($folder, 'KTAPI_Folder')) { + $this->assertEqual($folders[$parentId][$folder->get_folderid()], $folderName); + } + + // Folder by Name in root folder (duplicate names) + $parentId = 1; + $folderName = 'Test api sub-folder TWO'; + // no parent required + $folder = $this->ktapi->get_folder_by_name($folderName); + $this->assertNotNull($folder); + $this->assertIsA($folder, 'KTAPI_Folder'); + $this->assertNoErrors(); + // confirm folder id matches expected + if (is_a($folder, 'KTAPI_Folder')) { + $this->assertEqual($folders[$parentId][$folder->get_folderid()], $folderName); + } + + // Folder Detail by Name in sub folder of root folder (duplicate names) + $parentId = $root_folder_id[0]; + $folderName = 'Test api sub-folder THREE'; + $response = $this->ktapi->get_folder_detail_by_name($folderName, $parentId); + $this->assertNotNull($response['results']); + $this->assertNoErrors(); + // confirm folder id matches expected + if (!empty($response)) { + $this->assertEqual($folders[$parentId][$response['results']['id']], $folderName); + } + + // Folder by Name in sub folder of sub folder (duplicate names) + $parentId = $sub_folder_id[0][0]; + $folderName = 'Test api sub-folder TWO'; + $folder = $this->ktapi->get_folder_by_name($folderName, $parentId); + $this->assertNotNull($folder); + $this->assertIsA($folder, 'KTAPI_Folder'); + $this->assertNoErrors(); + // confirm folder id matches expected + if (is_a($folder, 'KTAPI_Folder')) { + $this->assertEqual($folders[$parentId][$folder->get_folderid()], $folderName); + } + + // Clean up - delete all of the folders + foreach ($root_folder_id as $folder_id) { + $this->ktapi->delete_folder($folder_id, 'Testing API', KT_TEST_USER, KT_TEST_PASS); + } + + foreach ($sub_folder_id as $_folder_id_) { + foreach ($_folder_id_ as $folder_id) { + $this->ktapi->delete_folder($folder_id, 'Testing API', KT_TEST_USER, KT_TEST_PASS); + } + } + } /** * Helper function to create a document diff --git a/tests/runtests.php b/tests/runtests.php index be73a73..6e99b4f 100644 --- a/tests/runtests.php +++ b/tests/runtests.php @@ -38,6 +38,10 @@ class UnitTests extends TestSuite { // are not on, so if you have failures, check there first :) $this->addFile('api/testElectronicSignatures.php'); + // Web Service tests + $this->addFile('webservices/testRest.php'); + $this->addFile('webservices/testSoap.php'); + // $this->addFile('SQLFile/test_sqlfile.php'); // $this->addFile('cache/testCache.php'); // $this->addFile('config/testConfig.php'); diff --git a/tests/webservices/testRest.php b/tests/webservices/testRest.php index 8261613..6fdf14c 100644 --- a/tests/webservices/testRest.php +++ b/tests/webservices/testRest.php @@ -137,6 +137,210 @@ class RESTTestCase extends KTUnitTestCase { $this->assertTrue(empty($response['results'])); $this->assertTrue(!empty($response['message'])); } + + /** + * Tests finding of a folder or folder detail by name + * Runs the following sub-tests: + * . Root folder Folder by Name (root folder test) + * . Folder Detail by Name in root folder (no duplicate names) + * . Folder Detail by name in subfolder of root folder (no duplicate names) + * . Folder by Name in subfolder of root folder (no duplicate names) + * . Folder by Name in root folder (duplicate names) + * . Folder Detail by name in subfolder of root folder (duplicate names) + * . Folder by name in subfolder of root folder (duplicate names) + */ + public function testGetFolderByName() + { + // Login and authenticate + $url = $this->rootUrl.'method=login&password=admin&username=admin'; + $response = $this->call($url); + $response = $response['response']; + + $this->assertEqual($response['status_code'], 0); + $session_id = $response['results']; + + // set up + $root_folder_id = array(); + $sub_folder_id = array(); + $folders[0][1] = 'Root Folder'; + + // Create a sub folder in the root folder + $parentId = 1; + $folderName = 'Test api sub-folder ONE'; + $url = $this->rootUrl.'method=create_folder&session_id=' . $session_id . '&folder_id=' . $parentId . '&folder_name=' . urlencode($folderName); + $response = $this->call($url); + $response = $response['response']; + $root_folder_id[] = $response['results']['id']; + $folders[$parentId][$response['results']['id']] = $folderName; + $this->assertEqual($response['status_code'], 0); + + // Create a second sub folder in the root folder + $parentId = 1; + $folderName = 'Test api sub-folder TWO'; + $url = $this->rootUrl.'method=create_folder&session_id=' . $session_id . '&folder_id=' . $parentId . '&folder_name=' . urlencode($folderName); + $response = $this->call($url); + $response = $response['response']; + $root_folder_id[] = $response['results']['id']; + $folders[$parentId][$response['results']['id']] = $folderName; + $this->assertEqual($response['status_code'], 0); + + // Create a sub folder in the first sub folder + $parentId = $root_folder_id[0]; + $folderName = 'Test api sub-folder THREE'; + $url = $this->rootUrl.'method=create_folder&session_id=' . $session_id . '&folder_id=' . $parentId . '&folder_name=' . urlencode($folderName); + $response = $this->call($url); + $response = $response['response']; + $sub_folder_id[0][] = $response['results']['id']; + $folders[$parentId][$response['results']['id']] = $folderName; + $this->assertEqual($response['status_code'], 0); + + // Create a sub folder within the first sub folder which shares a name with one of the root sub folders + $parentId = $sub_folder_id[0][0]; + $folderName = 'Test api sub-folder TWO'; + $url = $this->rootUrl.'method=create_folder&session_id=' . $session_id . '&folder_id=' . $parentId . '&folder_name=' . urlencode($folderName); + $response = $this->call($url); + $response = $response['response']; + $sub_folder_id[0][] = $response['results']['id']; + $folders[$parentId][$response['results']['id']] = $folderName; + $this->assertEqual($response['status_code'], 0); + + // Create a second sub folder in the first sub folder + $parentId = $root_folder_id[0]; + $folderName = 'Test api sub-folder FOUR'; + $url = $this->rootUrl.'method=create_folder&session_id=' . $session_id . '&folder_id=' . $parentId . '&folder_name=' . urlencode($folderName); + $response = $this->call($url); + $response = $response['response']; + $sub_folder_id[0][] = $response['results']['id']; + $folders[$parentId][$response['results']['id']] = $folderName; + $this->assertEqual($response['status_code'], 0); + + // Create a sub folder within the second sub folder + $parentId = $root_folder_id[1]; + $folderName = 'Test api sub-folder FIVE'; + $url = $this->rootUrl.'method=create_folder&session_id=' . $session_id . '&folder_id=' . $parentId . '&folder_name=' . urlencode($folderName); + $response = $this->call($url); + $response = $response['response']; + $sub_folder_id[1][] = $response['results']['id']; + $folders[$parentId][$response['results']['id']] = $folderName; + $this->assertEqual($response['status_code'], 0); + + // Create a sub folder within the second sub folder which shares a name with a sub folder in the first sub folder + $parentId = $sub_folder_id[1][0]; + $folderName = 'Test api sub-folder THREE'; + $url = $this->rootUrl.'method=create_folder&session_id=' . $session_id . '&folder_id=' . $parentId . '&folder_name=' . urlencode($folderName); + $response = $this->call($url); + $response = $response['response']; + $sub_folder_id[1][] = $response['results']['id']; + $folders[$parentId][$response['results']['id']] = $folderName; + $this->assertEqual($response['status_code'], 0); + + // NOTE default parent is 1, so does not need to be declared when searching the root folder, but we use it elsewhere + + // Fetching of root folder + $parentId = 0; + $folderName = 'Root Folder'; + $url = $this->rootUrl.'method=get_folder_detail_by_name&session_id=' . $session_id . '&folder_name=' . urlencode($folderName); + $response = $this->call($url); + $response = $response['response']; + $this->assertEqual($response['status_code'], 0); + $this->assertFalse(!empty($response['message'])); + if (($response['status_code'] == 0)) { + $this->assertEqual($folders[$parentId][$response['results']['id']], $folderName); + } + + // Folder Detail by Name in root folder (no duplicate names) + $parentId = 1; + $folderName = 'Test api sub-folder ONE'; + // no parent required + $url = $this->rootUrl.'method=get_folder_detail_by_name&session_id=' . $session_id . '&folder_name=' . urlencode($folderName); + $response = $this->call($url); + $response = $response['response']; + $this->assertEqual($response['status_code'], 0); + $this->assertFalse(!empty($response['message'])); + if (($response['status_code'] == 0)) { + $this->assertEqual($folders[$parentId][$response['results']['id']], $folderName); + } + + // Folder Detail by Name in sub folder of root folder (no duplicate names) + $parentId = $root_folder_id[0]; + $folderName = 'Test api sub-folder FOUR'; + $url = $this->rootUrl.'method=get_folder_detail_by_name&session_id=' . $session_id . '&parent_id=' . $parentId . '&folder_name=' . urlencode($folderName); + $response = $this->call($url); + $response = $response['response']; + $this->assertEqual($response['status_code'], 0); + $this->assertFalse(!empty($response['message'])); + if (($response['status_code'] == 0)) { + $this->assertEqual($folders[$parentId][$response['results']['id']], $folderName); + } + + // Folder Detail by Name in root folder (duplicate names) + $parentId = 1; + $folderName = 'Test api sub-folder TWO'; + $url = $this->rootUrl.'method=get_folder_detail_by_name&session_id=' . $session_id . '&parent_id=' . $parentId . '&folder_name=' . urlencode($folderName); + $response = $this->call($url); + $response = $response['response']; + $this->assertEqual($response['status_code'], 0); + $this->assertFalse(!empty($response['message'])); + if (($response['status_code'] == 0)) { + $this->assertEqual($folders[$parentId][$response['results']['id']], $folderName); + } + + // Folder Detail by Name in sub folder of root folder (duplicate names) + $parentId = $root_folder_id[0]; + $folderName = 'Test api sub-folder THREE'; + $url = $this->rootUrl.'method=get_folder_detail_by_name&session_id=' . $session_id . '&parent_id=' . $parentId . '&folder_name=' . urlencode($folderName); + $response = $this->call($url); + $response = $response['response']; + $this->assertEqual($response['status_code'], 0); + $this->assertFalse(!empty($response['message'])); + if (($response['status_code'] == 0)) { + $this->assertEqual($folders[$parentId][$response['results']['id']], $folderName); + } + + // Negative test with non duplicated folder - look for folder in location it does not exist + $parentId = $root_folder_id[0]; + $folderName = 'Test api sub-folder ONE'; + $url = $this->rootUrl.'method=get_folder_detail_by_name&session_id=' . $session_id . '&parent_id=' . $parentId . '&folder_name=' . urlencode($folderName); + $response = $this->call($url); + $response = $response['response']; + $this->assertNotEqual($response['status_code'], 0); + $this->assertTrue(!empty($response['message'])); + $this->assertNotEqual($folders[$parentId][$response['results']['id']], $folderName); + + // Negative test with duplicated folder - look for folder with incorrect parent id, result should not match expected folder + $parentId = 1; + $actualParentId = $sub_folder_id[0][0]; + $folderName = 'Test api sub-folder TWO'; + $url = $this->rootUrl.'method=get_folder_detail_by_name&session_id=' . $session_id . '&parent_id=' . $parentId . '&folder_name=' . urlencode($folderName); + $response = $this->call($url); + $response = $response['response']; + // we should get a result + $this->assertEqual($response['status_code'], 0); + $this->assertFalse(!empty($response['message'])); + // but not the one we wanted + $url = $this->rootUrl.'method=get_folder_detail_by_name&session_id=' . $session_id . '&parent_id=' . $actualParentId . '&folder_name=' . urlencode($folderName); + $expectedResponse = $this->call($url); + $expectedResponse = $expectedResponse['response']; + $this->assertNotEqual($response['results']['id'], $expectedResponse['results']['id']); + + // Clean up - delete all of the folders + foreach ($root_folder_id as $folder_id) { + $url = $this->rootUrl.'method=delete_folder&session_id=' . $session_id . '&folder_id=' . $folder_id . '&reason=Testing%20Webservice'; + $this->call($url); + } + + foreach ($sub_folder_id as $_folder_id_) { + foreach ($_folder_id_ as $folder_id) { + $url = $this->rootUrl.'method=delete_folder&session_id=' . $session_id . '&folder_id=' . $folder_id . '&reason=Testing%20Webservice'; + $this->call($url); + } + } + + // Logout + $url = $this->rootUrl.'method=logout&session_id='.$session_id; + $response = $this->call($url); + $response = $response['response']; + } /** * Convert xml into an array structure diff --git a/tests/webservices/testSoap.php b/tests/webservices/testSoap.php new file mode 100644 index 0000000..855194a --- /dev/null +++ b/tests/webservices/testSoap.php @@ -0,0 +1,265 @@ +rootUrl = $url.'/ktwebservice/webservice.php?'; + $this->user = isset($_GET['user']) ? $_GET['user'] : 'admin'; + $this->pass = isset($_GET['pass']) ? $_GET['pass'] : 'admin'; + } + + /** + * This method is a placeholder + */ + public function tearDown() + { + } + + function connect() + { + $wsdl = $this->rootUrl . "wsdl"; + $this->client = new SoapClient($wsdl); + } + + function login($ip = null) + { + $res = $this->client->__soapCall("login", array($this->user, $this->pass, $ip)); + if($res->status_code != 0){ + return false; + } + $this->session = $res->message; + } + + + function getDocTypes() + { + $result = $this->client->__soapCall("get_document_types", array($this->session)); + return $result->document_types; + } + + function search($expr) + { + $result = $this->client->__soapCall("search", array($this->session, $expr, '')); + return $result->hits; + } + + function getFolderDetail($folder, $parentId = 1) + { + $result = $this->client->__soapCall("get_folder_detail_by_name", array($this->session, $folder, $parentId)); + return $result; + } + + function createFolder($parent_id, $folder) + { + $result = $this->client->__soapCall("create_folder", array($this->session, $parent_id, $folder)); + return $result; + } + + function deleteFolder($folder_id) + { + $result = $this->client->__soapCall("delete_folder", array($this->session, "$folder_id", 'Testing')); + return $result; + } + + function logout() + { + $result = $this->client->__soapCall("logout", array($this->session)); + if($result->status_code != 0){ + return true; + } + } + + // now the test functions + + /** + * Tests finding of a folder or folder detail by name + * Runs the following sub-tests: + * . Folder Detail by Name in root folder (no duplicate names) + * . Folder Detail by Name in subfolder of root folder (no duplicate names) + * . Folder Detail by Name in subfolder of root folder (duplicate names) + * + * NOTE there are less tests here because we cannot test the get_folder_by_name function since it does not exist within the web service code + */ + public function testGetFolderByName() + { + // Login and authenticate + $this->connect(); + $this->login('127.0.0.1'); + + // set up + $root_folder_id = array(); + $sub_folder_id = array(); + $folders[0][1] = 'Root Folder'; + + // Create a sub folder in the root folder + $parentId = 1; + $folderName = 'Test api sub-folder ONE'; + $response = $this->createFolder($parentId, $folderName); + $root_folder_id[] = $response->id; + $folders[$parentId][$response->id] = $folderName; + $this->assertEqual($response->status_code, 0); + $this->assertFalse(!empty($response->message)); + + // Create a second sub folder in the root folder + $parentId = 1; + $folderName = 'Test api sub-folder TWO'; + $response = $this->createFolder($parentId, $folderName); + $root_folder_id[] = $response->id; + $folders[$parentId][$response->id] = $folderName; + $this->assertEqual($response->status_code, 0); + $this->assertFalse(!empty($response->message)); + + // Create a sub folder in the first sub folder + $parentId = $root_folder_id[0]; + $folderName = 'Test api sub-folder THREE'; + $response = $this->createFolder($parentId, $folderName); + $sub_folder_id[0][] = $response->id; + $folders[$parentId][$response->id] = $folderName; + $this->assertEqual($response->status_code, 0); + $this->assertFalse(!empty($response->message)); + + // Create a sub folder within the first sub folder which shares a name with one of the root sub folders + $parentId = $sub_folder_id[0][0]; + $folderName = 'Test api sub-folder TWO'; + $response = $this->createFolder($parentId, $folderName); + $sub_folder_id[0][] = $response->id; + $folders[$parentId][$response->id] = $folderName; + $this->assertEqual($response->status_code, 0); + $this->assertFalse(!empty($response->message)); + + // Create a second sub folder in the first sub folder + $parentId = $root_folder_id[0]; + $folderName = 'Test api sub-folder FOUR'; + $response = $this->createFolder($parentId, $folderName); + $sub_folder_id[0][] = $response->id; + $folders[$parentId][$response->id] = $folderName; + $this->assertEqual($response->status_code, 0); + $this->assertFalse(!empty($response->message)); + + // Create a sub folder within the second sub folder + $parentId = $root_folder_id[1]; + $folderName = 'Test api sub-folder FIVE'; + $response = $this->createFolder($parentId, $folderName); + $sub_folder_id[1][] = $response->id; + $folders[$parentId][$response->id] = $folderName; + $this->assertEqual($response->status_code, 0); + $this->assertFalse(!empty($response->message)); + + // Create a sub folder within the second sub folder which shares a name with a sub folder in the first sub folder + $parentId = $sub_folder_id[1][0]; + $folderName = 'Test api sub-folder THREE'; + $response = $this->createFolder($parentId, $folderName); + $sub_folder_id[1][] = $response->id; + $folders[$parentId][$response->id] = $folderName; + $this->assertEqual($response->status_code, 0); + $this->assertFalse(!empty($response->message)); + + // NOTE default parent is 1, so does not need to be declared when searching the root folder, but we use it elsewhere + + // Fetching of root folder + $parentId = 0; + $folderName = 'Root Folder'; + $response = $this->getFolderDetail($folderName); + $this->assertEqual($response->status_code, 0); + $this->assertFalse(!empty($response->message)); + if (($response->status_code == 0)) { + $this->assertEqual($folders[$parentId][$response->id], $folderName); + } + + // Folder Detail by Name in root folder (no duplicate names) + $parentId = 1; + $folderName = 'Test api sub-folder ONE'; + // no parent required + $response = $this->getFolderDetail($folderName); + $this->assertEqual($response->status_code, 0); + $this->assertFalse(!empty($response->message)); + if (($response->status_code == 0)) { + $this->assertEqual($folders[$parentId][$response->id], $folderName); + } + + // Folder Detail by Name in sub folder of root folder (no duplicate names) + $parentId = $root_folder_id[0]; + $folderName = 'Test api sub-folder FOUR'; + $response = $this->getFolderDetail($folderName, $parentId); + $this->assertEqual($response->status_code, 0); + $this->assertFalse(!empty($response->message)); + if (($response->status_code == 0)) { + $this->assertEqual($folders[$parentId][$response->id], $folderName); + } + + // Folder Detail by Name in root folder (duplicate names) + $parentId = 1; + $folderName = 'Test api sub-folder TWO'; + $response = $this->getFolderDetail($folderName, $parentId); + $this->assertEqual($response->status_code, 0); + $this->assertFalse(!empty($response->message)); + if (($response->status_code == 0)) { + $this->assertEqual($folders[$parentId][$response->id], $folderName); + } + + // Folder Detail by Name in sub folder of root folder (duplicate names) + $parentId = $root_folder_id[0]; + $folderName = 'Test api sub-folder THREE'; + $response = $this->getFolderDetail($folderName, $parentId); + $this->assertEqual($response->status_code, 0); + $this->assertFalse(!empty($response->message)); + if (($response->status_code == 0)) { + $this->assertEqual($folders[$parentId][$response->id], $folderName); + } + + // Negative test with non duplicated folder - look for folder in location it does not exist + $parentId = $root_folder_id[0]; + $folderName = 'Test api sub-folder ONE'; + $response = $this->getFolderDetail($folderName, $parentId); + $this->assertNotEqual($response->status_code, 0); + $this->assertTrue(!empty($response->message)); + $this->assertNotEqual($folders[$parentId][$response->id], $folderName); + + // Negative test with duplicated folder - look for folder with incorrect parent id, result should not match expected folder + $parentId = 1; + $actualParentId = $sub_folder_id[0][0]; + $folderName = 'Test api sub-folder TWO'; + $response = $this->getFolderDetail($folderName, $parentId); + // we should get a result + $this->assertEqual($response->status_code, 0); + $this->assertFalse(!empty($response->message)); + // but not the one we wanted + $expectedResponse = $this->getFolderDetail($folderName, $actualParentId); + $this->assertNotEqual($response->id, $expectedResponse->id); + + // Clean up - delete all of the folders + foreach ($root_folder_id as $folder_id) { + $this->deleteFolder($folder_id); + } + + // Logout + $this->logout(); + } + +} +?> \ No newline at end of file