Commit f626f7b0584a81bfce7c7c4a13afa5aa7542173e

Authored by megan
2 parents 5983de1b 8ae04922

Merge branch 'master' of git@github.com:ktgit/knowledgetree

ktapi/KTAPIDocument.inc.php
... ... @@ -2285,7 +2285,7 @@ class KTAPI_Document extends KTAPI_FolderItem
2285 2285 *
2286 2286 * @author KnowledgeTree Team
2287 2287 * @access public
2288   - * @return bool TRUE if subscribed | FALSE if not
  2288 + * @return bool $result TRUE if subscribed | FALSE if not
2289 2289 */
2290 2290 public function isSubscribed()
2291 2291 {
... ... @@ -2293,7 +2293,8 @@ class KTAPI_Document extends KTAPI_FolderItem
2293 2293 $user = $this->ktapi->get_user();
2294 2294 $document = $this->document;
2295 2295  
2296   - return Subscription::exists($user->getId(), $document->getId(), $subscriptionType);
  2296 + $result = Subscription::exists($user->getId(), $document->getId(), $subscriptionType);
  2297 + return $result;
2297 2298 }
2298 2299  
2299 2300 /**
... ... @@ -2301,12 +2302,13 @@ class KTAPI_Document extends KTAPI_FolderItem
2301 2302 *
2302 2303 * @author KnowledgeTree Team
2303 2304 * @access public
  2305 + * @return boolean|object $result SUCCESS Boolean result of operation | FAILURE - a pear error object
2304 2306 */
2305 2307 public function unsubscribe()
2306 2308 {
2307 2309 if (!$this->isSubscribed())
2308 2310 {
2309   - return;
  2311 + return TRUE;
2310 2312 }
2311 2313  
2312 2314 $subscriptionType = SubscriptionEvent::subTypes('Document');
... ... @@ -2314,7 +2316,16 @@ class KTAPI_Document extends KTAPI_FolderItem
2314 2316 $document = $this->document;
2315 2317  
2316 2318 $subscription = & Subscription::getByIDs($user->getId(), $document->getId(), $subscriptionType);
2317   - $subscription->delete();
  2319 + $result = $subscription->delete();
  2320 +
  2321 + if(PEAR::isError($result)){
  2322 + return $result->getMessage();
  2323 + }
  2324 + if($result){
  2325 + return $result;
  2326 + }
  2327 +
  2328 + return $_SESSION['errorMessage'];
2318 2329 }
2319 2330  
2320 2331 /**
... ... @@ -2322,12 +2333,13 @@ class KTAPI_Document extends KTAPI_FolderItem
2322 2333 *
2323 2334 * @author KnowledgeTree Team
2324 2335 * @access public
  2336 + * @return boolean|object $result SUCCESS Boolean result of operation | FAILURE - a pear error object
2325 2337 */
2326 2338 public function subscribe()
2327 2339 {
2328 2340 if ($this->isSubscribed())
2329 2341 {
2330   - return;
  2342 + return TRUE;
2331 2343 }
2332 2344  
2333 2345 $subscriptionType = SubscriptionEvent::subTypes('Document');
... ... @@ -2335,7 +2347,16 @@ class KTAPI_Document extends KTAPI_FolderItem
2335 2347 $document = $this->document;
2336 2348  
2337 2349 $subscription = new Subscription($user->getId(), $document->getId(), $subscriptionType);
2338   - $subscription->create();
  2350 + $result = $subscription->create();
  2351 +
  2352 + if(PEAR::isError($result)){
  2353 + return $result->getMessage();
  2354 + }
  2355 + if($result){
  2356 + return $result;
  2357 + }
  2358 +
  2359 + return $_SESSION['errorMessage'];
2339 2360 }
2340 2361  
2341 2362 /**
... ... @@ -2456,4 +2477,4 @@ class KTAPI_Document extends KTAPI_FolderItem
2456 2477 }
2457 2478 }
2458 2479  
2459 2480 -?>
  2481 +?>
2460 2482 \ No newline at end of file
... ...
ktapi/KTAPIFolder.inc.php
... ... @@ -1192,7 +1192,8 @@ class KTAPI_Folder extends KTAPI_FolderItem
1192 1192 $user = $this->ktapi->get_user();
1193 1193 $folder = $this->folder;
1194 1194  
1195   - return Subscription::exists($user->getId(), $folder->getId(), $subscriptionType);
  1195 + $result = Subscription::exists($user->getId(), $folder->getId(), $subscriptionType);
  1196 + return $result;
1196 1197 }
1197 1198  
1198 1199 /**
... ... @@ -1205,7 +1206,7 @@ class KTAPI_Folder extends KTAPI_FolderItem
1205 1206 {
1206 1207 if (!$this->isSubscribed())
1207 1208 {
1208   - return;
  1209 + return TRUE;
1209 1210 }
1210 1211  
1211 1212 $subscriptionType = SubscriptionEvent::subTypes('Folder');
... ... @@ -1213,7 +1214,16 @@ class KTAPI_Folder extends KTAPI_FolderItem
1213 1214 $folder = $this->folder;
1214 1215  
1215 1216 $subscription = & Subscription::getByIDs($user->getId(), $folder->getId(), $subscriptionType);
1216   - $subscription->delete();
  1217 + $result = $subscription->delete();
  1218 +
  1219 + if(PEAR::isError($result)){
  1220 + return $result->getMessage();
  1221 + }
  1222 + if($result){
  1223 + return $result;
  1224 + }
  1225 +
  1226 + return $_SESSION['errorMessage'];
1217 1227 }
1218 1228  
1219 1229 /**
... ... @@ -1227,17 +1237,24 @@ class KTAPI_Folder extends KTAPI_FolderItem
1227 1237 {
1228 1238 if ($this->isSubscribed())
1229 1239 {
1230   - return;
  1240 + return TRUE;
1231 1241 }
1232   -
1233   - $subscriptionType = SubscriptionEvent::subTypes('Folder ');
  1242 + $subscriptionType = SubscriptionEvent::subTypes('Folder');
1234 1243 $user = $this->ktapi->get_user();
1235 1244 $folder = $this->folder;
1236 1245  
1237 1246 $subscription = new Subscription($user->getId(), $folder->getId(), $subscriptionType);
1238   - $subscription->create();
1239   - }
  1247 + $result = $subscription->create();
1240 1248  
  1249 + if(PEAR::isError($result)){
  1250 + return $result->getMessage();
  1251 + }
  1252 + if($result){
  1253 + return $result;
  1254 + }
  1255 +
  1256 + return $_SESSION['errorMessage'];
  1257 + }
1241 1258 }
1242 1259  
1243 1260 -?>
  1261 +?>
1244 1262 \ No newline at end of file
... ...
ktapi/ktapi.inc.php
... ... @@ -298,6 +298,39 @@ class KTAPI
298 298 );
299 299  
300 300 }
  301 +
  302 + /**
  303 + * Returns folder permissions
  304 + *
  305 + * @access public
  306 + * @param string
  307 + * @param int
  308 + *
  309 + */
  310 + public function get_document_permissions($username, $document_id) {
  311 + if (is_null($this->session))
  312 + {
  313 + return array(
  314 + "status_code" => 1,
  315 + "message" => "Your session is not active"
  316 + );
  317 + }
  318 + /* We need to create a new instance of KTAPI to get another user */
  319 + $user_ktapi = new KTAPI();
  320 + $user_ktapi->start_system_session($username);
  321 +
  322 + $document = KTAPI_Document::get($user_ktapi, $document_id);
  323 +
  324 + $permissions = $document->getPermissionAllocation();
  325 +
  326 + $user_ktapi->session_logout();
  327 +
  328 + return array(
  329 + "status_code" => 0,
  330 + "results" => $permissions->permissions
  331 + );
  332 +
  333 + }
301 334  
302 335 /**
303 336 * Add folder permission
... ... @@ -3978,7 +4011,7 @@ class KTAPI
3978 4011 * @param string $query The saved search query
3979 4012 * @return array $response The formatted response array
3980 4013 */
3981   - public function createSavedSearch($name, $query)
  4014 + public function create_saved_search($name, $query)
3982 4015 {
3983 4016 $savedSearch = new savedSearches($this);
3984 4017 if(PEAR::isError($savedSearch)){
... ... @@ -4009,7 +4042,7 @@ class KTAPI
4009 4042 * @param string $searchID The id of the saved search
4010 4043 * @return array $response The formatted response array
4011 4044 */
4012   - public function getSavedSearch($searchID)
  4045 + public function get_saved_search($searchID)
4013 4046 {
4014 4047 $savedSearch = new savedSearches($this);
4015 4048 if(PEAR::isError($savedSearch)){
... ... @@ -4018,7 +4051,7 @@ class KTAPI
4018 4051 return $response;
4019 4052 }
4020 4053  
4021   - $result = $savedSearch->getSavedSearch($searchID);
  4054 + $result = $savedSearch->get_saved_search($searchID);
4022 4055 if(PEAR::isError($result)){
4023 4056 $response['status_code'] = 1;
4024 4057 $response['message'] = $result->getMessage();
... ... @@ -4045,7 +4078,7 @@ class KTAPI
4045 4078 * @access public
4046 4079 * @return array $response The formatted response array
4047 4080 */
4048   - public function getSavedSearchList()
  4081 + public function get_saved_search_list()
4049 4082 {
4050 4083 $savedSearch = new savedSearches($this);
4051 4084 if(PEAR::isError($savedSearch)){
... ... @@ -4054,7 +4087,7 @@ class KTAPI
4054 4087 return $response;
4055 4088 }
4056 4089  
4057   - $result = $savedSearch->getList();
  4090 + $result = $savedSearch->get_list();
4058 4091 if(PEAR::isError($result)){
4059 4092 $response['status_code'] = 1;
4060 4093 $response['message'] = $result->getMessage();
... ... @@ -4082,7 +4115,7 @@ class KTAPI
4082 4115 * @param string $searchID The id of the saved search to delete
4083 4116 * @return array $response The formatted response array
4084 4117 */
4085   - public function deleteSavedSearch($searchID)
  4118 + public function delete_saved_search($searchID)
4086 4119 {
4087 4120 $savedSearch = new savedSearches($this);
4088 4121 if(PEAR::isError($savedSearch)){
... ... @@ -4112,7 +4145,7 @@ class KTAPI
4112 4145 * @param string $searchID The id of the saved search to delete
4113 4146 * @return array $response The formatted response array
4114 4147 */
4115   - public function runSavedSearch($searchID)
  4148 + public function run_saved_search($searchID)
4116 4149 {
4117 4150 $savedSearch = new savedSearches($this);
4118 4151 if(PEAR::isError($savedSearch)){
... ... @@ -4121,7 +4154,7 @@ class KTAPI
4121 4154 return $response;
4122 4155 }
4123 4156  
4124   - $results = $savedSearch->runSavedSearch($searchID);
  4157 + $results = $savedSearch->run_saved_search($searchID);
4125 4158 if(PEAR::isError($results)){
4126 4159 $response['status_code'] = 1;
4127 4160 $response['message'] = $results->getMessage();
... ... @@ -4137,6 +4170,298 @@ class KTAPI
4137 4170  
4138 4171 return $response;
4139 4172 }
  4173 +
  4174 + /**
  4175 + * Method to get the details of a user
  4176 + *
  4177 + * @author KnowledgeTree Team
  4178 + * @access private
  4179 + * @param object $oUser The user object
  4180 + * @return array $results The user details in an array
  4181 + */
  4182 + private function _get_user_details($oUser)
  4183 + {
  4184 + $results['user_id'] = $oUser->getId();
  4185 + $results['username'] = $oUser->getUsername();
  4186 + $results['name'] = $oUser->getName();
  4187 + $results['email'] = $oUser->getEmail();
  4188 +
  4189 + return $results;
  4190 + }
  4191 +
  4192 + /**
  4193 + * Method to return a user based on the userID
  4194 + *
  4195 + * @author KnowledgeTree Team
  4196 + * @access public
  4197 + * @param string $userID The id of the user
  4198 + * @return array $response The formatted response array
  4199 + */
  4200 + public function get_user_by_id($userID)
  4201 + {
  4202 + $user = KTAPI_User::getById($userID);
  4203 + if(PEAR::isError($user)){
  4204 + $response['status_code'] = 1;
  4205 + $response['message'] = $user->getMessage();
  4206 + return $response;
  4207 + }
  4208 +
  4209 + $results = $this->_get_user_details($user);
  4210 + $response['message'] = '';
  4211 + $response['status_code'] = 0;
  4212 + $response['results'] = $results;
  4213 +
  4214 + return $response;
  4215 + }
  4216 +
  4217 + /**
  4218 + * Method to return a user based on the username
  4219 + *
  4220 + * @author KnowledgeTree Team
  4221 + * @access public
  4222 + * @param string $username The username of the user
  4223 + * @return array $response The formatted response array
  4224 + */
  4225 + public function get_user_by_username($username)
  4226 + {
  4227 + $user = KTAPI_User::getByUsername($username);
  4228 + if(PEAR::isError($user)){
  4229 + $response['status_code'] = 1;
  4230 + $response['message'] = $user->getMessage();
  4231 + return $response;
  4232 + }
  4233 +
  4234 + $results = $this->_get_user_details($user);
  4235 + $response['message'] = '';
  4236 + $response['status_code'] = 0;
  4237 + $response['results'] = $results;
  4238 +
  4239 + return $response;
  4240 + }
  4241 +
  4242 + /**
  4243 + * Method to return a user based on the name
  4244 + *
  4245 + * @author KnowledgeTree Team
  4246 + * @access public
  4247 + * @param string $name The name of the user
  4248 + * @return array $response The formatted response array
  4249 + */
  4250 + public function get_user_by_name($name)
  4251 + {
  4252 + $user = KTAPI_User::getByName($name);
  4253 + if(PEAR::isError($user)){
  4254 + $response['status_code'] = 1;
  4255 + $response['message'] = $user->getMessage();
  4256 + return $response;
  4257 + }
  4258 +
  4259 + $results = $this->_get_user_details($user);
  4260 + $response['message'] = '';
  4261 + $response['status_code'] = 0;
  4262 + $response['results'] = $results;
  4263 +
  4264 + return $response;
  4265 + }
  4266 +
  4267 + /**
  4268 + * Method to return a list of users matching the filter criteria
  4269 + *
  4270 + * @author KnowledgeTree Team
  4271 + * @access public
  4272 + * @param string $filter
  4273 + * @param string $options
  4274 + * @return array $response The formatted response array
  4275 + */
  4276 + public function get_user_list($filter = NULL, $options = NULL)
  4277 + {
  4278 + $users = KTAPI_User::getList($filter, $options);
  4279 + if(PEAR::isError($users)){
  4280 + $response['status_code'] = 1;
  4281 + $response['message'] = $users->getMessage();
  4282 + return $response;
  4283 + }
  4284 + foreach($users as $user){
  4285 + $results[] = $this->_get_user_details($user);
  4286 + }
  4287 + $response['message'] = '';
  4288 + $response['status_code'] = 0;
  4289 + $response['results'] = $results;
  4290 +
  4291 + return $response;
  4292 + }
  4293 +
  4294 + /**
  4295 + * Method to check if a document is subscribed
  4296 + *
  4297 + * @author KnowledgeTree Team
  4298 + * @access public
  4299 + * @param string $documentID The id of the document
  4300 + * @return array $response The formatted response array
  4301 + */
  4302 + public function is_document_subscribed($documentID)
  4303 + {
  4304 + $document = $this->get_document_by_id($documentID);
  4305 + if(PEAR::isError($document)){
  4306 + $response['message'] = $document->getMessage();
  4307 + $response['status_code'] = 1;
  4308 + return $response;
  4309 + }
  4310 +
  4311 + $result = $document->isSubscribed();
  4312 + $response['message'] = '';
  4313 + $response['status_code'] = 0;
  4314 + if($result){
  4315 + $response['results']['subscribed'] = 'TRUE';
  4316 + }else{
  4317 + $response['results']['subscribed'] = 'FALSE';
  4318 + }
  4319 + return $response;
  4320 + }
  4321 +
  4322 + /**
  4323 + * Method to subscribe to a document
  4324 + *
  4325 + * @author KnowledgeTree Team
  4326 + * @access public
  4327 + * @param string $documentID The id of the document
  4328 + * @return array $response The formatted response array
  4329 + */
  4330 + public function subscribe_to_document($documentID)
  4331 + {
  4332 + $document = $this->get_document_by_id($documentID);
  4333 + if(PEAR::isError($document)){
  4334 + $response['message'] = $document->getMessage();
  4335 + $response['status_code'] = 1;
  4336 + return $response;
  4337 + }
  4338 +
  4339 + $result = $document->subscribe();
  4340 + if($result === TRUE){
  4341 + $response['message'] = '';
  4342 + $response['status_code'] = 0;
  4343 + $response['results']['action_result'] = 'TRUE';
  4344 + }else{
  4345 + $response['message'] = $result;
  4346 + $response['status_code'] = 1;
  4347 + }
  4348 + return $response;
  4349 + }
  4350 +
  4351 + /**
  4352 + * Method to unsubscribe from a document
  4353 + *
  4354 + * @author KnowledgeTree Team
  4355 + * @access public
  4356 + * @param string $documentID The id of the document
  4357 + * @return array $response The formatted response array
  4358 + */
  4359 + public function unsubscribe_from_document($documentID)
  4360 + {
  4361 + $document = $this->get_document_by_id($documentID);
  4362 + if(PEAR::isError($document)){
  4363 + $response['message'] = $document->getMessage();
  4364 + $response['status_code'] = 1;
  4365 + return $response;
  4366 + }
  4367 +
  4368 + $result = $document->unsubscribe();
  4369 + if($result === TRUE){
  4370 + $response['message'] = '';
  4371 + $response['status_code'] = 0;
  4372 + $response['results']['action_result'] = 'TRUE';
  4373 + }else{
  4374 + $response['message'] = $result;
  4375 + $response['status_code'] = 1;
  4376 + }
  4377 + return $response;
  4378 + }
  4379 +
  4380 + /**
  4381 + * Method to check if a folder is subscribed
  4382 + *
  4383 + * @author KnowledgeTree Team
  4384 + * @access public
  4385 + * @param string $folderID The id of the folder
  4386 + * @return array $response The formatted response array
  4387 + */
  4388 + public function is_folder_subscribed($folderID)
  4389 + {
  4390 + $folder = $this->get_folder_by_id($folderID);
  4391 + if(PEAR::isError($folder)){
  4392 + $response['message'] = $folder->getMessage();
  4393 + $response['status_code'] = 1;
  4394 + return $response;
  4395 + }
  4396 +
  4397 + $result = $folder->isSubscribed();
  4398 + $response['message'] = '';
  4399 + $response['status_code'] = 0;
  4400 + if($result){
  4401 + $response['results']['subscribed'] = 'TRUE';
  4402 + }else{
  4403 + $response['results']['subscribed'] = 'FALSE';
  4404 + }
  4405 + return $response;
  4406 + }
  4407 +
  4408 + /**
  4409 + * Method to subscribe to a folder
  4410 + *
  4411 + * @author KnowledgeTree Team
  4412 + * @access public
  4413 + * @param string $folderID The id of the folder
  4414 + * @return array $response The formatted response array
  4415 + */
  4416 + public function subscribe_to_folder($folderID)
  4417 + {
  4418 + $folder = $this->get_folder_by_id($folderID);
  4419 + if(PEAR::isError($folder)){
  4420 + $response['message'] = $folder->getMessage();
  4421 + $response['status_code'] = 1;
  4422 + return $response;
  4423 + }
  4424 +
  4425 + $result = $folder->subscribe();
  4426 + if($result === TRUE){
  4427 + $response['message'] = '';
  4428 + $response['status_code'] = 0;
  4429 + $response['results']['action_result'] = 'TRUE';
  4430 + }else{
  4431 + $response['message'] = $result;
  4432 + $response['status_code'] = 1;
  4433 + }
  4434 + return $response;
  4435 + }
  4436 +
  4437 + /**
  4438 + * Method to unsubscribe from a folder
  4439 + *
  4440 + * @author KnowledgeTree Team
  4441 + * @access public
  4442 + * @param string $folderID The id of the folder
  4443 + * @return array $response The formatted response array
  4444 + */
  4445 + public function unsubscribe_from_folder($folderID)
  4446 + {
  4447 + $folder = $this->get_folder_by_id($folderID);
  4448 + if(PEAR::isError($folder)){
  4449 + $response['message'] = $folder->getMessage();
  4450 + $response['status_code'] = 1;
  4451 + return $response;
  4452 + }
  4453 +
  4454 + $result = $folder->unsubscribe();
  4455 + if($result === TRUE){
  4456 + $response['message'] = '';
  4457 + $response['status_code'] = 0;
  4458 + $response['results']['action_result'] = 'TRUE';
  4459 + }else{
  4460 + $response['message'] = $result;
  4461 + $response['status_code'] = 1;
  4462 + }
  4463 + return $response;
  4464 + }
4140 4465 }
4141 4466  
4142 4467  
... ... @@ -4200,7 +4525,7 @@ class savedSearches
4200 4525 * @param integer $searchID The id of the saved search
4201 4526 * @return array|object $search SUCESS - The saved search data | FAILURE - a pear error object
4202 4527 */
4203   - public function getSavedSearch($searchID)
  4528 + public function get_saved_search($searchID)
4204 4529 {
4205 4530 $search = SearchHelper::getSavedSearch($searchID);
4206 4531 return $search;
... ... @@ -4213,7 +4538,7 @@ class savedSearches
4213 4538 * @access public
4214 4539 * @return array|object $list SUCESS - The list of saved searches | FAILURE - an error object
4215 4540 */
4216   - public function getList()
  4541 + public function get_list()
4217 4542 {
4218 4543 $user = $this->ktapi->get_user();
4219 4544 if (is_null($user) || PEAR::isError($user))
... ... @@ -4253,9 +4578,9 @@ class savedSearches
4253 4578 * @param integer $searchID The id of the saved search
4254 4579 * @return array|object $results SUCCESS - The results of the saved serach | FAILURE - a pear error object
4255 4580 */
4256   - public function runSavedSearch($searchID)
  4581 + public function run_saved_search($searchID)
4257 4582 {
4258   - $search = $this->getSavedSearch($searchID);
  4583 + $search = $this->get_saved_search($searchID);
4259 4584 if(is_null($search) || PEAR::isError($search)){
4260 4585 $results = new PEAR_Error('Invalid saved search');
4261 4586 return $results;
... ... @@ -4266,4 +4591,5 @@ class savedSearches
4266 4591 return $results;
4267 4592 }
4268 4593 }
  4594 +
4269 4595 ?>
4270 4596 \ No newline at end of file
... ...
templates/ktcore/login.smarty
... ... @@ -11,8 +11,10 @@
11 11  
12 12 <link rel="stylesheet" href="{$rootUrl}/resources/css/kt-ie-icons.css" type="text/css" />
13 13  
14   - <script type="text/javascript" src="{$rootUrl}/thirdpartyjs/curvycorners/rounded_corners.inc.js"> </script>
15   - <script type="text/javascript" src="{$rootUrl}/resources/js/login_loader.js"> </script>
  14 + <!--
  15 + <script type="text/javascript" src="{$rootUrl}/thirdpartyjs/curvycorners/rounded_corners.inc.js"> </script>
  16 + <script type="text/javascript" src="{$rootUrl}/resources/js/login_loader.js"> </script>
  17 + -->
16 18 </head>
17 19 <body>
18 20 <div id="loginbox_outer" {if ($disclaimer)} class="hasDisclaimer" {/if}>
... ...
tests/api/testAcl.php
... ... @@ -190,6 +190,36 @@ class APIAclTestCase extends KTUnitTestCase {
190 190  
191 191 }
192 192  
  193 + /**
  194 + * Method to test the user webservice fucntions
  195 + *
  196 + */
  197 + public function testUsers_KTAPI()
  198 + {
  199 + $response = $this->ktapi->get_user_list();
  200 + $this->assertIsA($response, 'array');
  201 + $this->assertEqual($response['status_code'], 0);
  202 + $this->assertNoErrors();
  203 +
  204 + $response = $this->ktapi->get_user_by_id(1);
  205 + $this->assertIsA($response, 'array');
  206 + $this->assertEqual($response['status_code'], 0);
  207 + $this->assertEqual($response['results']['name'], 'Administrator');
  208 + $this->assertNoErrors();
  209 +
  210 + $response = $this->ktapi->get_user_by_username('admin');
  211 + $this->assertIsA($response, 'array');
  212 + $this->assertEqual($response['status_code'], 0);
  213 + $this->assertEqual($response['results']['name'], 'Administrator');
  214 + $this->assertNoErrors();
  215 +
  216 + $response = $this->ktapi->get_user_by_name('Administrator');
  217 + $this->assertIsA($response, 'array');
  218 + $this->assertEqual($response['status_code'], 0);
  219 + $this->assertEqual($response['results']['name'], 'Administrator');
  220 + $this->assertNoErrors();
  221 + }
  222 +
193 223 /**
194 224 * Test KTAPI_Group getList(), getById(), getByName
195 225 *
... ...
tests/api/testDocument.php
... ... @@ -395,5 +395,65 @@ class APIDocumentTestCase extends KTUnitTestCase {
395 395 }
396 396 }
397 397 */
  398 +
  399 + /**
  400 + * Method to test the document subscriptions for webservices
  401 + *
  402 + */
  403 + public function testSubscriptions_KTAPI()
  404 + {
  405 + $this->ktapi->session_logout();
  406 + $this->session = $this->ktapi->start_session('admin', 'admin');
  407 +
  408 + $randomFile = APIDocumentHelper::createRandomFile();
  409 + $this->assertTrue(is_file($randomFile));
  410 +
  411 + $document = $this->root->add_document('testtitle.txt', 'testname.txt', 'Default', $randomFile);
  412 + $this->assertIsA($document, 'KTAPI_Document');
  413 + $this->assertNoErrors();
  414 +
  415 + @unlink($randomFile);
  416 + $documentid = $document->get_documentid();
  417 +
  418 + // case no subscription
  419 + $response = $this->ktapi->is_document_subscribed($documentid);
  420 + $this->assertIsA($response, 'array');
  421 + $this->assertEqual($response['results']['subscribed'], 'FALSE');
  422 + $this->assertNoErrors();
  423 +
  424 + //case add subscription
  425 + $response = $this->ktapi->subscribe_to_document($documentid);
  426 + $this->assertIsA($response, 'array');
  427 + $this->assertEqual($response['results']['action_result'], 'TRUE');
  428 + $this->assertNoErrors();
  429 +
  430 + //case add DUPLICATE subscription
  431 + $response = $this->ktapi->subscribe_to_document($documentid);
  432 + $this->assertIsA($response, 'array');
  433 + $this->assertEqual($response['results']['action_result'], 'TRUE');
  434 + $this->assertNoErrors();
  435 +
  436 + // case subscription exists
  437 + $response = $this->ktapi->is_document_subscribed($documentid);
  438 + $this->assertIsA($response, 'array');
  439 + $this->assertEqual($response['results']['subscribed'], 'TRUE');
  440 + $this->assertNoErrors();
  441 +
  442 + //case delete subscription
  443 + $response = $this->ktapi->unsubscribe_from_document($documentid);
  444 + $this->assertIsA($response, 'array');
  445 + $this->assertEqual($response['results']['action_result'], 'TRUE');
  446 + $this->assertNoErrors();
  447 +
  448 + //case delete NOT EXISTANT subscription
  449 + $response = $this->ktapi->unsubscribe_from_document($documentid);
  450 + $this->assertIsA($response, 'array');
  451 + $this->assertEqual($response['results']['action_result'], 'TRUE');
  452 + $this->assertNoErrors();
  453 +
  454 + $document->delete('Test');
  455 + $document->expunge();
  456 + }
398 457 }
399   -?>
  458 +
  459 +?>
400 460 \ No newline at end of file
... ...
tests/api/testFolder.php
... ... @@ -200,10 +200,65 @@ class APIFolderTestCase extends KTUnitTestCase {
200 200  
201 201 $folder->delete('testXXXXX');
202 202 }
203   -
  203 +
204 204 function testTransactionHistory() {
205 205 $transactions = $this->ktapi->get_folder_transaction_history(1);
206 206 $this->assertIsA($transactions, 'array');
207 207 }
  208 +
  209 + /**
  210 + * Method to test the folder subscriptions for webservices
  211 + *
  212 + */
  213 + public function testSubscriptions_KTAPI()
  214 + {
  215 + $this->ktapi->session_logout();
  216 + $this->session = $this->ktapi->start_session('admin', 'admin');
  217 +
  218 + $root = $this->ktapi->get_root_folder();
  219 + $folder = $root->add_folder('testXXXXX');
  220 + $this->assertIsA($folder, 'KTAPI_Folder');
  221 + $this->assertNotA($folder, 'PEAR_Error');
  222 + $this->assertNoErrors();
  223 +
  224 + // case no subscription
  225 + $response = $this->ktapi->is_folder_subscribed($folder->get_folderid());
  226 + $this->assertIsA($response, 'array');
  227 + $this->assertEqual($response['results']['subscribed'], 'FALSE');
  228 + $this->assertNoErrors();
  229 +
  230 + //case add subscription
  231 + $response = $this->ktapi->subscribe_to_folder($folder->get_folderid());
  232 + $this->assertIsA($response, 'array');
  233 + $this->assertEqual($response['results']['action_result'], 'TRUE');
  234 + $this->assertNoErrors();
  235 +
  236 + //case add DUPLICATE subscription
  237 + $response = $this->ktapi->subscribe_to_folder($folder->get_folderid());
  238 + $this->assertIsA($response, 'array');
  239 + $this->assertEqual($response['results']['action_result'], 'TRUE');
  240 + $this->assertNoErrors();
  241 +
  242 + // case subscription exists
  243 + $response = $this->ktapi->is_folder_subscribed($folder->get_folderid());
  244 + $this->assertIsA($response, 'array');
  245 + $this->assertEqual($response['results']['subscribed'], 'TRUE');
  246 + $this->assertNoErrors();
  247 +
  248 + //case delete subscription
  249 + $response = $this->ktapi->unsubscribe_from_folder($folder->get_folderid());
  250 + $this->assertIsA($response, 'array');
  251 + $this->assertEqual($response['results']['action_result'], 'TRUE');
  252 + $this->assertNoErrors();
  253 +
  254 + //case delete NOT EXISTANT subscription
  255 + $response = $this->ktapi->unsubscribe_from_folder($folder->get_folderid());
  256 + $this->assertIsA($response, 'array');
  257 + $this->assertEqual($response['results']['action_result'], 'TRUE');
  258 + $this->assertNoErrors();
  259 +
  260 + $folder->delete('testXXXXX');
  261 + }
208 262 }
209   -?>
  263 +
  264 +?>
210 265 \ No newline at end of file
... ...
tests/api/testSavedSearches.php
... ... @@ -79,7 +79,7 @@ class savedSearchTestCase extends KTUnitTestCase {
79 79 {
80 80 // case 1: search exists
81 81 $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")');
82   - $list = $this->savedSearch->getList();
  82 + $list = $this->savedSearch->get_list();
83 83  
84 84 foreach($list as $item){
85 85 if($item['id'] == $searchID){
... ... @@ -87,14 +87,14 @@ class savedSearchTestCase extends KTUnitTestCase {
87 87 break;
88 88 }
89 89 }
90   - $savedSearch = $this->savedSearch->getSavedSearch($search);
  90 + $savedSearch = $this->savedSearch->get_saved_search($search);
91 91  
92 92 $this->assertNotNull($savedSearch);
93 93 $this->assertNoErrors();
94 94 $this->savedSearch->delete($searchID);
95 95  
96 96 // case 2: search does NOT exists
97   - $list = $this->savedSearch->getList();
  97 + $list = $this->savedSearch->get_list();
98 98 $inList = FALSE;
99 99 foreach($list as $item){
100 100 if($item['id'] == $searchID){
... ... @@ -118,7 +118,7 @@ class savedSearchTestCase extends KTUnitTestCase {
118 118 // case 1: Saved searches exist
119 119 $array = array();
120 120 $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")');
121   - $list = $this->savedSearch->getList();
  121 + $list = $this->savedSearch->get_list();
122 122 $this->assertNotA($list, 'PEAR_Error');
123 123 $this->assertNotEqual($list, $array);
124 124 $this->assertNoErrors();
... ... @@ -126,7 +126,7 @@ class savedSearchTestCase extends KTUnitTestCase {
126 126 $this->savedSearch->delete($searchID);
127 127  
128 128 // case 2: saved search does NOT exist
129   - $list = $this->savedSearch->getList();
  129 + $list = $this->savedSearch->get_list();
130 130  
131 131 $inList = FALSE;
132 132 foreach($list as $item){
... ... @@ -148,7 +148,7 @@ class savedSearchTestCase extends KTUnitTestCase {
148 148 {
149 149 $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")');
150 150 $this->savedSearch->delete($searchID);
151   - $result = $this->savedSearch->getSavedSearch($searchID);
  151 + $result = $this->savedSearch->get_saved_search($searchID);
152 152  
153 153 $array = array();
154 154 $this->assertEqual($result, $array);
... ... @@ -169,7 +169,7 @@ class savedSearchTestCase extends KTUnitTestCase {
169 169  
170 170 $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")');
171 171  
172   - $result = $this->savedSearch->runSavedSearch($searchID);
  172 + $result = $this->savedSearch->run_saved_search($searchID);
173 173  
174 174 $this->assertNotNull($result);
175 175 $this->assertNotA($result, 'PEAR_Error');
... ... @@ -188,7 +188,7 @@ class savedSearchTestCase extends KTUnitTestCase {
188 188 public function testCreate_KTAPI()
189 189 {
190 190 //case 1: user logged in
191   - $response = $this->ktapi->createSavedSearch('test_search', '(GeneralText contains "title")');
  191 + $response = $this->ktapi->create_saved_search('test_search', '(GeneralText contains "title")');
192 192  
193 193 $this->assertIsA($response, 'array');
194 194 $this->assertEqual($response['status_code'], 0);
... ... @@ -198,7 +198,7 @@ class savedSearchTestCase extends KTUnitTestCase {
198 198  
199 199 //case 2: user NOT logged in
200 200 $this->ktapi->session_logout();
201   - $response = $this->ktapi->createSavedSearch('test_search', '(GeneralText contains "title")');
  201 + $response = $this->ktapi->create_saved_search('test_search', '(GeneralText contains "title")');
202 202  
203 203 $this->assertIsA($response, 'array');
204 204 $this->assertEqual($response['status_code'], 1);
... ... @@ -213,7 +213,7 @@ class savedSearchTestCase extends KTUnitTestCase {
213 213 {
214 214 // case 1: search exists
215 215 $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")');
216   - $list = $this->savedSearch->getList();
  216 + $list = $this->savedSearch->get_list();
217 217  
218 218 foreach($list as $item){
219 219 if($item['id'] == $searchID){
... ... @@ -221,7 +221,7 @@ class savedSearchTestCase extends KTUnitTestCase {
221 221 break;
222 222 }
223 223 }
224   - $response = $this->ktapi->getSavedSearch($search);
  224 + $response = $this->ktapi->get_saved_search($search);
225 225  
226 226 $this->assertIsA($response, 'array');
227 227 $this->assertEqual($response['status_code'], 0);
... ... @@ -229,7 +229,7 @@ class savedSearchTestCase extends KTUnitTestCase {
229 229 $this->savedSearch->delete($searchID);
230 230  
231 231 // case 2: search does NOT exists
232   - $response = $this->ktapi->getSavedSearch($searchID);
  232 + $response = $this->ktapi->get_saved_search($searchID);
233 233  
234 234 $this->assertIsA($response, 'array');
235 235 $this->assertEqual($response['status_code'], 1);
... ... @@ -247,7 +247,7 @@ class savedSearchTestCase extends KTUnitTestCase {
247 247 $array = array();
248 248 $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")');
249 249  
250   - $response = $this->ktapi->getSavedSearchList();
  250 + $response = $this->ktapi->get_saved_search_list();
251 251  
252 252 $this->assertIsA($response, 'array');
253 253 $this->assertEqual($response['status_code'], 0);
... ... @@ -255,7 +255,7 @@ class savedSearchTestCase extends KTUnitTestCase {
255 255 $this->savedSearch->delete($searchID);
256 256  
257 257 // case 2: saved search does NOT exist
258   - $response = $this->ktapi->getSavedSearchList();
  258 + $response = $this->ktapi->get_saved_search_list();
259 259  
260 260 $this->assertIsA($response, 'array');
261 261 $this->assertEqual($response['status_code'], 1);
... ... @@ -269,8 +269,8 @@ class savedSearchTestCase extends KTUnitTestCase {
269 269 public function testDelete_KTAPI()
270 270 {
271 271 $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")');
272   - $response = $this->ktapi->deleteSavedSearch($searchID);
273   - $result = $this->savedSearch->getSavedSearch($searchID);
  272 + $response = $this->ktapi->delete_saved_search($searchID);
  273 + $result = $this->savedSearch->get_saved_search($searchID);
274 274  
275 275 $array = array();
276 276 $this->assertEqual($result, $array);
... ... @@ -292,7 +292,7 @@ class savedSearchTestCase extends KTUnitTestCase {
292 292  
293 293 $searchID = $this->savedSearch->create('test_search', '(GeneralText contains "title")');
294 294  
295   - $response = $this->ktapi->runSavedSearch($searchID);
  295 + $response = $this->ktapi->run_saved_search($searchID);
296 296  
297 297 $this->assertIsA($response, 'array');
298 298 $this->assertEqual($response['status_code'], 0);
... ...