function testStoreEventsDoNotOverrideUsers()
 {
     $listeningUsers = new ArrayIterator(array(array('user_id' => 1, 'object_id' => 1), array('user_id' => 2, 'object_id' => 1), array('user_id' => 3, 'object_id' => 1)));
     $user1 = new MockUser();
     $user1->setReturnValue('getId', 1);
     $user2 = new MockUser();
     $user2->setReturnValue('getId', 2);
     $user3 = new MockUser();
     $user3->setReturnValue('getId', 3);
     $um = new MockUserManager();
     $um->setReturnValueAt(0, 'getUserById', $user1);
     $um->setReturnValueAt(1, 'getUserById', $user2);
     $um->setReturnValueAt(2, 'getUserById', $user3);
     $dpm = new MockDocman_PermissionsManager();
     $dpm->setReturnValue('userCanRead', true);
     $dpm->setReturnValue('userCanAccess', true);
     $item = new MockDocman_Item();
     $item->setReturnValue('getId', 1);
     $params = array('item' => $item);
     $nm = new Docman_NotificationsManager_DeleteTestVersion();
     $nm->setReturnValue('_getListeningUsers', $listeningUsers);
     $nm->setReturnValue('_getUserManager', $um);
     $nm->setReturnValue('_getPermissionsManager', $dpm);
     $nm->_listeners = array();
     $nm->_storeEvents(1, 'removed', $params);
     $this->assertEqual($user1, $nm->_listeners[1]['user']);
     $this->assertEqual($user2, $nm->_listeners[2]['user']);
     $this->assertEqual($user3, $nm->_listeners[3]['user']);
 }
 public function testRemoveMailByProjectPrivateRepositoryErrorDaoRemoving()
 {
     $prm = new PostReceiveMailManagerTestVersion();
     $user = new MockUser($this);
     $user->setReturnValue('isMember', False);
     $user->setReturnValue('getEmail', "*****@*****.**");
     $prj = new MockProject($this);
     $prj->setReturnValue('getId', 1750);
     $repositoryList = array(array('project_id' => '1750', 'repository_id' => 2515));
     $gitDao = new MockGitDao($this);
     $prm->setReturnValue('_getGitDao', $gitDao);
     $gitDao->setReturnValue('getProjectRepositoryList', $repositoryList);
     foreach ($repositoryList as $row) {
         $repo = new MockGitRepository($this);
         $prm->setReturnValue('_getGitRepository', $repo);
         $repo->setReturnValue('isPrivate', True);
         $repo->setReturnValue('load', True);
         $backend = new MockGitBackend();
         $repo->SetReturnValue('getBackend', $backend);
     }
     $prm->setReturnValue('removeMailByRepository', False);
     $GLOBALS['Language']->setReturnValue('getText', 'Mail not removed');
     $GLOBALS['Response']->expectOnce('addFeedback', array('error', $GLOBALS['Language']->getText('plugin_git', 'dao_error_remove_notification')));
     $prm->removeMailByProjectPrivateRepository($prj->getId(), $user);
 }
Esempio n. 3
0
 function testGetDisplayNameForNone()
 {
     $user = new MockUser($this);
     $user->setReturnValue('isNone', true);
     $user->setReturnValue('getUserName', 'None');
     $user->setReturnValue('getRealName', '0');
     $um = new MockUserManager();
     $um->setReturnValue('isUserLoadedById', true, array(100));
     $um->setReturnReference('getUserById', $user, array(100));
     $uh = new UserHelperTestVersion($this);
     $uh->setReturnValue('_getUserManager', $um);
     $uh->setReturnValue('_isUserNameNone', true, array('None'));
     $uh->setReturnValue('_isUserNameNone', true, array('Aucun'));
     $uh->setReturnValue('_getCurrentUserUsernameDisplayPreference', 4);
     $uh->setReturnValueAt(0, '_getCurrentUserUsernameDisplayPreference', 1);
     $uh->setReturnValueAt(1, '_getCurrentUserUsernameDisplayPreference', 2);
     $uh->setReturnValueAt(2, '_getCurrentUserUsernameDisplayPreference', 3);
     $uh->__construct();
     $this->assertEqual("None", $uh->getDisplayNameFromUser($user));
     $uh->__construct();
     $this->assertEqual("None", $uh->getDisplayNameFromUser($user));
     $uh->__construct();
     $this->assertEqual("None", $uh->getDisplayNameFromUser($user));
     $uh->__construct();
     $this->assertEqual("None", $uh->getDisplayNameFromUser($user));
     $this->assertEqual("None", $uh->getDisplayNameFromUserId(100));
     $this->assertEqual("None", $uh->getDisplayNameFromUserName("None"));
     $this->assertEqual("Aucun", $uh->getDisplayNameFromUserName("Aucun"));
 }
Esempio n. 4
0
 private function GivenAUserManagerThatIsProgrammedToThrow($exception)
 {
     $adminUser = new MockUser();
     $adminUser->setReturnValue('isLoggedIn', true);
     $um = new MockUserManager();
     $um->setReturnValue('getCurrentUser', $adminUser);
     $um->throwOn('loginAs', $exception);
     $server = new User_SOAPServer($um);
     return new UserManagerAsserter($server, $this);
 }
Esempio n. 5
0
 public function testCanRenameUserWithUserAlreadyQueudedForRename()
 {
     $user = new MockUser();
     $user->setReturnValue('getId', 102);
     $seDao = new MockSystemEventDao($this);
     $dar = new MockDataAccessResult($this);
     $dar->setReturnValue('rowCount', 1);
     $seDao->setReturnValue('searchWithParam', $dar);
     $seDao->expectOnce('searchWithParam', array('head', 102, array(SystemEvent::TYPE_USER_RENAME), array(SystemEvent::STATUS_NEW, SystemEvent::STATUS_RUNNING)));
     $se = new SystemEventManagerTestVersion($this);
     $se->setReturnValue('_getDao', $seDao);
     $this->assertFalse($se->canRenameUser($user));
 }
 function testRevokeUserFromPrivilegeList()
 {
     $usDao = new MockAdminDelegation_UserServiceDao($this);
     $usDao->expectOnce('removeUserService', array(112, AdminDelegation_Service::SHOW_PROJECT_ADMINS));
     $usDao->setReturnValue('removeUserService', true);
     $uslDao = new MockAdminDelegation_UserServiceLogDao($this);
     $uslDao->expectOnce('addLog', array('revoke', AdminDelegation_Service::SHOW_PROJECT_ADMINS, 112, 1259333681));
     $usm = new AdminDelegation_UserServiceManagerTestVersion($this);
     $usm->setReturnValue('_getUserServiceDao', $usDao);
     $usm->setReturnValue('_getUserServiceLogDao', $uslDao);
     $user = new MockUser($this);
     $user->setReturnValue('getId', 112);
     $usm->removeUserService($user, AdminDelegation_Service::SHOW_PROJECT_ADMINS);
 }
Esempio n. 7
0
 function testValidateRecipient()
 {
     $mail = new Codendi_MailTestVersion($this);
     $user1 = new MockUser();
     $user1->setReturnValue('getRealName', 'user 1');
     $user1->setReturnValue('getEmail', '*****@*****.**');
     $user1->setReturnValue('getStatus', 'A');
     $user2 = new MockUser();
     $user2->setReturnValue('getRealName', 'user 2');
     $user2->setReturnValue('getEmail', '*****@*****.**');
     $user2->setReturnValue('getStatus', 'S');
     $recipArray = array($user1, $user2);
     $recipients = $mail->_validateRecipient($recipArray);
     $retArray = array(array('real_name' => $user1->getRealName(), 'email' => $user1->getEmail()));
     $this->assertEqual($recipients, $retArray);
 }
Esempio n. 8
0
 public function setUp()
 {
     $GLOBALS['Language'] = new MockBaseLanguage($this);
     // Mock instanciation
     $controller = new MockDocman_SOAPController();
     $controller->feedback = new MockFeedback();
     $version = new MockDocman_Version();
     $version->setReturnValue('getNumber', 0);
     $this->itemFactory = new MockDocman_ItemFactory();
     $folderFactory = new MockDocman_FolderFactory();
     $this->fileStorage = new MockDocman_FileStorage();
     // Item MD5 Map: id => md5sum
     $this->MD5Map = array(128000 => '99999999999999999999999999999999');
     foreach ($this->MD5Map as $itemId => $md5) {
         $file = new MockDocman_File();
         $file->setReturnValue('getID', $itemId);
         $file->setReturnValue('getCurrentVersion', $version);
         $this->itemFactory->setReturnValue('getItemFromDb', $file, array($itemId));
         $this->itemFactory->setReturnValue('getItemTypeForItem', PLUGIN_DOCMAN_ITEM_TYPE_FILE, array($file));
         $this->fileStorage->setReturnValue('getFileMD5sum', $md5);
     }
     $user = new MockUser();
     $user->setReturnValue('getId', 9);
     $userManager = new MockUserManager();
     $userManager->setReturnValue('getUserById', $user);
     $userManager->setReturnValue('getUserByUserName', $user);
     $userManager->setReturnValue('getCurrentUser', $user);
     $controller->setReturnValue('getUser', $user);
     $versionFactory = new MockDocman_VersionFactory();
     $versionFactory->setReturnValue('getAllVersionForItem', array($version));
     $this->lockFactory = new MockDocman_LockFactory();
     $this->permissionManager = new MockPermissionsManager();
     $this->docmanPermissionsManager = new MockDocman_PermissionsManager();
     $this->docmanPermissionsManager->setReturnValue('getLockFactory', $this->lockFactory);
     // Partial mock of Docman_SOAPActions
     $this->action = new Docman_SOAPActions_Test();
     $this->action->setReturnValue('_getItemFactory', $this->itemFactory);
     $this->action->setReturnValue('_getFolderFactory', $folderFactory);
     $this->action->setReturnValue('_checkOwnerChange', 101, array('*', '*'));
     $this->action->setReturnValue('_getUserManagerInstance', $userManager);
     $this->action->setReturnValue('_getVersionFactory', $versionFactory);
     $this->action->setReturnValue('_getPermissionsManagerInstance', $this->permissionManager);
     $this->action->setReturnValue('_getDocmanPermissionsManagerInstance', $this->docmanPermissionsManager);
     $this->action->setReturnValue('_getEventManager', new MockEventManager());
     $this->action->setReturnValue('_getFileStorage', $this->fileStorage);
     $this->action->__construct($controller);
 }
 function testUpdateShouldUpdateAllProjects()
 {
     $id = 1002;
     $type = LDAP_UserManager::EVENT_UPDATE_LOGIN;
     $parameters = '101::102';
     $priority = SystemEvent::PRIORITY_MEDIUM;
     $status = SystemEvent::STATUS_RUNNING;
     $create_date = '';
     $process_date = '';
     $end_date = '';
     $log = '';
     $se = TestHelper::getPartialMock('SystemEvent_PLUGIN_LDAP_UPDATE_LOGIN', array('getUserManager', 'getBackendSVN', 'getProject'));
     $user1 = new MockUser();
     $user1->setReturnValue('getAllProjects', array(201, 202));
     $user1->setReturnValue('isActive', true);
     $user2 = new MockUser();
     $user2->setReturnValue('getAllProjects', array(202, 203));
     $user2->setReturnValue('isActive', true);
     $um = new MockUserManager();
     $um->setReturnValue('getUserById', $user1, array('101'));
     $um->setReturnValue('getUserById', $user2, array('102'));
     $se->setReturnValue('getUserManager', $um);
     $prj1 = new MockProject();
     $prj2 = new MockProject();
     $prj3 = new MockProject();
     $se->setReturnValue('getProject', $prj1, array(201));
     $se->setReturnValue('getProject', $prj2, array(202));
     $se->setReturnValue('getProject', $prj3, array(203));
     $backend = new MockBackendSVN();
     $backend->expectCallCount('updateProjectSVNAccessFile', 3);
     $backend->expect('updateProjectSVNAccessFile', array($prj1));
     $backend->expect('updateProjectSVNAccessFile', array($prj2));
     $backend->expect('updateProjectSVNAccessFile', array($prj3));
     $se->setReturnValue('getBackendSVN', $backend);
     $se->__construct($id, $type, $parameters, $priority, $status, $create_date, $process_date, $end_date, $log);
     $se->process();
 }
Esempio n. 10
0
 function testCheckRestrictedAccessUserIsMember()
 {
     $GLOBALS['sys_allow_restricted_users'] = 1;
     $pm = new ProjectManagerTestVersion();
     $um = new MockUserManager();
     $user = new MockUser();
     $user->setReturnValue('isRestricted', true);
     $um->setReturnValue('getCurrentUser', $user);
     $pm->setReturnValue('_getUserManager', $um);
     $project = new MockProject();
     $project->setReturnValue('userIsMember', true);
     $this->assertTrue($pm->checkRestrictedAccess($project));
     $pm->expectOnce('_getUserManager');
 }
 public function testUpdateSVNAccessFailure()
 {
     $evt = new SystemEvent_USER_RENAME_TestVersion($this);
     $evt->__construct('1', SystemEvent::TYPE_USER_RENAME, '142' . SystemEvent::PARAMETER_SEPARATOR . 'tazmani', SystemEvent::PRIORITY_HIGH, SystemEvent::STATUS_RUNNING, $_SERVER['REQUEST_TIME'], $_SERVER['REQUEST_TIME'], $_SERVER['REQUEST_TIME'], '');
     // The user
     $user = new MockUser($this);
     $user->setReturnValue('getUserName', 'mickey');
     $evt->setReturnValue('getUser', $user, array('142'));
     // System
     $backendSystem = new MockBackendSystem($this);
     $backendSystem->setReturnValue('userHomeExists', true);
     $backendSystem->setReturnValue('isUserNameAvailable', true);
     $backendSystem->setReturnValue('renameUserHomeDirectory', true);
     $backendSystem->expectOnce('renameUserHomeDirectory', array($user, 'tazmani'));
     $evt->setReturnValue('getBackend', $backendSystem, array('System'));
     // DB
     $evt->setReturnValue('updateDB', true);
     // CVS
     $backendCVS = new MockBackendCVS($this);
     $backendCVS->setReturnValue('updateCVSWritersForGivenMember', true);
     $evt->setReturnValue('getBackend', $backendCVS, array('CVS'));
     // SVN
     $backendSVN = new MockBackendSVN($this);
     $backendSVN->setReturnValue('updateSVNAccessForGivenMember', false);
     $evt->setReturnValue('getBackend', $backendSVN, array('SVN'));
     // There is an error, the rename is not "done"
     $evt->expectNever('done');
     $this->assertFalse($evt->process());
     // Check errors
     $this->assertEqual($evt->getStatus(), SystemEvent::STATUS_ERROR);
     $this->assertPattern('/Could not update SVN access files for the user/i', $evt->getLog());
 }
Esempio n. 12
0
 function testUserMustBeAdminOfTheDestinationProject()
 {
     $adminMsg = 'must_be_admin_to_create_project_repo';
     $GLOBALS['Language']->setReturnValue('getText', $adminMsg, array('plugin_git', $adminMsg, '*'));
     $user = new MockUser();
     $user->setReturnValue('isMember', false, array(666, 'A'));
     $request = new Codendi_Request(array('to_project' => 666, 'repos' => array(1)));
     $git = TestHelper::getPartialMock('Git', array('checkSynchronizerToken', 'addError', 'addAction'));
     $git->setGroupId(123);
     $git->expectOnce('addError', array($adminMsg));
     $git->expectNever('addAction');
     $git->_doDispatchForkCrossProject($request, $user);
 }
 function testChangesetShouldUseUserLanguageInBuildMessage()
 {
     $GLOBALS['Language']->expectNever('getText');
     $userLanguage = new MockBaseLanguage();
     $userLanguage->expectAtLeastOnce('getText');
     $user = new MockUser();
     $user->setReturnValue('getPreference', 'text', array('user_tracker_mailformat'));
     $user->setReturnValue('getLanguage', $userLanguage);
     $changeset = $this->buildChangeSet($user);
     $messages = array();
     $changeset->buildMessage($messages, true, $user, false);
 }
Esempio n. 14
0
 public function testLogGitPushSuccess()
 {
     $user = new MockUser();
     $user->setReturnValue('getId', 2);
     $um = new MockUserManager();
     $um->setReturnValue('getUserByIdentifier', $user);
     $repo = new GitRepositoryTestVersion();
     $repo->setReturnValue('_getUserManager', $um);
     $dao = new MockGitDao();
     $dao->setReturnValue('logGitPush', true);
     $repo->setReturnValue('getDao', $dao);
     $this->assertTrue($repo->logGitPush('repo', 'user', 'prj', 1327577111, 3));
     $repo->expectOnce('_getUserManager');
     $um->expectOnce('getUserByIdentifier');
     $user->expectOnce('getId');
     $dao->expectOnce('logGitPush');
 }
Esempio n. 15
0
 private function GivenASOAPServer()
 {
     $this->user = new MockUser();
     $this->user->setReturnValue('isLoggedIn', true);
     $admin = new MockUser();
     $admin->setReturnValue('isLoggedIn', true);
     $admin->setReturnValue('isSuperUser', true);
     $this->um = new MockUserManager();
     $this->um->setReturnValue('getCurrentUser', $this->user, array('123'));
     $this->um->setReturnValue('getCurrentUser', $admin, array('456'));
     $this->pm = new MockProjectManager();
     $this->pc = new MockProjectCreator();
     $this->limitator = new MockSOAP_RequestLimitator();
     $server = new Project_SOAPServer($this->pm, $this->pc, $this->um, $this->limitator);
     return $server;
 }
Esempio n. 16
0
<?php

include_once 'database.php';
include_once 'mock.php';
$user = new MockUser();
$result = $user->delete(1);
if ($result) {
    echo "We deleted a user!";
} else {
    echo "We did not delete a user.";
}
Esempio n. 17
0
 function testAdd_monitoringSuccess()
 {
     $controller = new MockDocman_Controller();
     $controller->feedback = new MockFeedback();
     $user = new MockUser();
     $user->setReturnValue('getId', 123);
     $user->setReturnValue('getName', 'Carol');
     $controller->feedback->expectOnce('log', array('info', '*'));
     $GLOBALS['Language']->expectOnce('getText', array('plugin_docman', 'notifications_added', array($user->getName())));
     $notificationsManager = new MockDocman_NotificationsManager();
     $notificationsManager->setReturnValue('exist', false);
     $notificationsManager->setReturnValue('add', true);
     $controller->notificationsManager = $notificationsManager;
     $actions = new Docman_ActionsTest();
     $actions->_controler = $controller;
     $actions->event_manager = new MockEventManager($this);
     $docmanPermissionsManager = new MockDocman_PermissionsManager();
     $docmanPermissionsManager->setReturnValue('userCanRead', true);
     $actions->setReturnValue('_getDocmanPermissionsManagerInstance', $docmanPermissionsManager);
     $params['listeners_to_add'] = array($user);
     $params['item'] = new MockDocman_Item();
     $params['invalid_users'] = false;
     $actions->add_monitoring($params);
     $notificationsManager->expectCallCount('exist', 1);
     $notificationsManager->expectCallCount('add', 1);
 }
Esempio n. 18
0
 public function testForkCrossProjectsRedirectToCrossProjectGitRepositories()
 {
     $repo_id = '1';
     $project_id = 2;
     $user = new MockUser();
     $user->setReturnValue('getId', 123);
     $user->setReturnValue('isMember', true, array($project_id, 'A'));
     $to_project = new MockProject();
     $to_project->setReturnValue('getId', $project_id);
     $repo = new MockGitRepository();
     $repo->setReturnValue('getId', $repo_id);
     $repo->setReturnValue('userCanRead', true, array($user));
     $repo->expectOnce('fork');
     $repos = array($repo);
     $systemEventManager = new MockSystemEventManager();
     $layout = new MockLayout();
     $layout->expectOnce('redirect');
     $action = $this->GivenAGitActions();
     $action->getController()->expectOnce('addInfo', array('successfully_forked'));
     $action->fork($repos, $to_project, '', null, $user, $layout, null);
 }
Esempio n. 19
0
 function testGetMessageForUserParentListened()
 {
     $language = new MockBaseLanguage();
     $language->setReturnValue('getText', 'notif_modified_by', array('plugin_docman', 'notif_modified_by'));
     $language->setReturnValue('getText', 'notif_wiki_new_version', array('plugin_docman', 'notif_wiki_new_version', 'wiki'));
     $language->setReturnValue('getText', 'notif_something_happen', array('plugin_docman', 'notif_something_happen'));
     $language->setReturnValue('getText', 'notif_footer_message', array('plugin_docman', 'notif_footer_message'));
     $language->setReturnValue('getText', 'notif_footer_message_link', array('plugin_docman', 'notif_footer_message_link'));
     $notificationsManager = new Docman_NotificationsManager_TestVersion();
     $notificationsManager->setReturnValue('_getLanguageForUser', $language);
     $notificationsManager->_url = 'http://www.example.com/plugins/docman/';
     $user = new MockUser();
     $user->setReturnValue('getRealName', 'John Doe');
     $user->setReturnValue('getId', 2);
     $params['path'] = new MockDocman_Path();
     $params['path']->setReturnValue('get', 'Folder1/Folder2/File');
     $params['item'] = new MockDocman_Item();
     $params['item']->setReturnValue('getId', 10);
     $parentItem = new MockDocman_Item();
     $parentItem->setReturnValue('getId', 1);
     $notificationsManager->setReturnValue('getListeningUsers', array($user->getId() => $parentItem));
     $params['wiki_page'] = 'wiki';
     $params['url'] = 'http://www.example.com/plugins/docman/';
     $message1 = "Folder1/Folder2/File notif_modified_by John Doe.\nhttp://www.example.com/plugins/docman/&action=details&id=10\n\n\n--------------------------------------------------------------------\nnotif_footer_message\nnotif_footer_message_link\nhttp://www.example.com/plugins/docman/&action=details&section=notifications&id=1";
     $message2 = "Folder1/Folder2/File notif_modified_by John Doe.\nhttp://www.example.com/plugins/docman/&action=details&id=10\n\n\n--------------------------------------------------------------------\nnotif_footer_message\nnotif_footer_message_link\nhttp://www.example.com/plugins/docman/&action=details&section=notifications&id=1";
     $message3 = "notif_wiki_new_version John Doe.\nhttp://www.example.com/plugins/docman/\n\n\n--------------------------------------------------------------------\nnotif_footer_message\nnotif_footer_message_link\nhttp://www.example.com/plugins/docman/&action=details&section=notifications&id=1";
     $message4 = "notif_something_happen\n\n--------------------------------------------------------------------\nnotif_footer_message\nnotif_footer_message_link\nhttp://www.example.com/plugins/docman/&action=details&section=notifications&id=1";
     $this->assertEqual($message1, $notificationsManager->_getMessageForUser($user, 'modified', $params));
     $this->assertEqual($message2, $notificationsManager->_getMessageForUser($user, 'new_version', $params));
     $this->assertEqual($message3, $notificationsManager->_getMessageForUser($user, 'new_wiki_version', $params));
     $this->assertEqual($message4, $notificationsManager->_getMessageForUser($user, 'something happen', $params));
 }
Esempio n. 20
0
 function testUserCanViewTrackerAccessSubmitterOrAssignee()
 {
     $ugroup_ass = 101;
     $ugroup_sub = 102;
     // $assignee and $u_ass are in the same ugroup (UgroupAss - ugroup_id=101)
     // $submitter and $u_sub are in the same ugroup (UgroupSub - ugroup_id=102)
     // $other and $u are neither in UgroupAss nor in UgroupSub
     //
     $u = new MockUser();
     $u->setReturnValue('getId', 120);
     $u->setReturnValue('isMemberOfUgroup', false);
     $u->setReturnValue('isSuperUser', false);
     //
     $assignee = new MockUser();
     $assignee->setReturnValue('getId', 121);
     $assignee->setReturnValue('isMemberOfUgroup', true, array(101, 222));
     $assignee->setReturnValue('isMemberOfUgroup', false, array(102, 222));
     $assignee->setReturnValue('isSuperUser', false);
     //
     $u_ass = new MockUser();
     $u_ass->setReturnValue('getId', 122);
     $u_ass->setReturnValue('isMemberOfUgroup', true, array(101, 222));
     $u_ass->setReturnValue('isMemberOfUgroup', false, array(102, 222));
     $u_ass->setReturnValue('isSuperUser', false);
     //
     $submitter = new MockUser();
     $submitter->setReturnValue('getId', 123);
     $submitter->setReturnValue('isMemberOfUgroup', false, array(101, 222));
     $submitter->setReturnValue('isMemberOfUgroup', true, array(102, 222));
     $submitter->setReturnValue('isSuperUser', false);
     //
     $u_sub = new MockUser();
     $u_sub->setReturnValue('getId', 124);
     $u_sub->setReturnValue('isMemberOfUgroup', false, array(101, 222));
     $u_sub->setReturnValue('isMemberOfUgroup', true, array(102, 222));
     $u_sub->setReturnValue('isSuperUser', false);
     //
     $other = new MockUser();
     $other->setReturnValue('getId', 125);
     $other->setReturnValue('isMemberOfUgroup', false);
     $other->setReturnValue('isSuperUser', false);
     $user_manager = new MockUserManager();
     $user_manager->setReturnReference('getUserById', $u, array(120));
     $user_manager->setReturnReference('getUserById', $assignee, array(121));
     $user_manager->setReturnReference('getUserById', $u_ass, array(122));
     $user_manager->setReturnReference('getUserById', $submitter, array(123));
     $user_manager->setReturnReference('getUserById', $u_sub, array(124));
     $user_manager->setReturnReference('getUserById', $other, array(125));
     // $artifact_subass has been submitted by $submitter and assigned to $assignee
     // $assignee, $u_ass, $submitter, $u_sub should have the right to see it.
     // $other and $u should not have the right to see it
     $tracker = new MockTracker();
     $tracker->setReturnValue('getId', 666);
     $tracker->setReturnValue('getGroupId', 222);
     $perms_tracker_access_full = array();
     $perms_tracker_access_assignee = array(array('ugroup_id' => $ugroup_ass));
     $perms_tracker_access_submitter = array(array('ugroup_id' => $ugroup_sub));
     $tracker->setReturnReference('permission_db_authorized_ugroups', $perms_tracker_access_full, array('PLUGIN_TRACKER_ACCESS_FULL'));
     $tracker->setReturnReference('permission_db_authorized_ugroups', $perms_tracker_access_assignee, array('PLUGIN_TRACKER_ACCESS_ASSIGNEE'));
     $tracker->setReturnReference('permission_db_authorized_ugroups', $perms_tracker_access_submitter, array('PLUGIN_TRACKER_ACCESS_SUBMITTER'));
     $contributor_field = new MockTracker_FormElement_Field();
     $tracker->setReturnReference('getContributorField', $contributor_field);
     $artifact_subass = new Tracker_ArtifactTestPermissions();
     $artifact_subass->setReturnReference('getUserManager', $user_manager);
     $artifact_subass->setReturnReference('getTracker', $tracker);
     $artifact_subass->setReturnValue('useArtifactPermissions', false);
     $artifact_subass->setReturnValue('getSubmittedBy', 123);
     $user_changeset_value = new MockTracker_Artifact_ChangesetValue();
     $contributors = array(121);
     $user_changeset_value->setReturnReference('getValue', $contributors);
     $artifact_subass->setReturnReference('getValue', $user_changeset_value, array($contributor_field));
     $this->assertTrue($artifact_subass->userCanView($submitter));
     $this->assertTrue($artifact_subass->userCanView($u_sub));
     $this->assertTrue($artifact_subass->userCanView($assignee));
     $this->assertTrue($artifact_subass->userCanView($u_ass));
     $this->assertFalse($artifact_subass->userCanView($other));
     $this->assertFalse($artifact_subass->userCanView($u));
 }
Esempio n. 21
0
 function testGetMailPrefsByUsersShouldReturnHTMLWhenPreferenceReturnsFalse()
 {
     $mm = new MailManager();
     $user = new MockUser();
     $user->expectOnce('getPreference', array('user_tracker_mailformat'));
     $user->setReturnValue('getPreference', false);
     $this->assertEqual($mm->getMailPreferencesByUser($user), Codendi_Mail_Interface::FORMAT_HTML);
 }
Esempio n. 22
0
 public function testHasErrorNoError()
 {
     $header = array('summary', 'details');
     $lines = array(array('summary 1', 'details 1'), array('summary 2', 'details 2'));
     $field1 = new MockTracker_FormElement_Field_String();
     $field2 = new MockTracker_FormElement_Field_String();
     $field1->setReturnValue('isRequired', false);
     $field2->setReturnValue('isRequired', false);
     $field1->setReturnValue('getId', 1);
     $field2->setReturnValue('getId', 2);
     $field1->setReturnValue('getFieldData', 'summary 1', array('summary 1'));
     $field1->setReturnValue('getFieldData', 'summary 2', array('summary 2'));
     $field2->setReturnValue('getFieldData', 'details 1', array('details 1'));
     $field2->setReturnValue('getFieldData', 'details 2', array('details 2'));
     $this->formelement_factory->setReturnReference('getUsedFieldByName', $field1, array(110, 'summary'));
     $this->formelement_factory->setReturnReference('getUsedFieldByName', $field2, array(110, 'details'));
     $artifact = new MockTracker_Artifact();
     $af = new MockTracker_ArtifactFactory();
     $this->tracker->setReturnReference('getTrackerArtifactFactory', $af);
     $this->tracker->setReturnValue('aidExists', false, array('0'));
     $artifact->setReturnValue('validateFields', true);
     $um = new MockUserManager();
     $u = new MockUser();
     $u->setReturnValue('getId', '107');
     $this->tracker->setReturnReference('getUserManager', $um);
     $um->setReturnReference('getCurrentUser', $u);
     $af->setReturnReference('getInstanceFromRow', $artifact);
     $GLOBALS['Response']->expectNever('addFeedback');
     $this->assertFalse($this->tracker->hasError($header, $lines));
 }
Esempio n. 23
0
 /**
  * Testing when project is public and user is member and restricted
  */
 function testUserCanReadWhenPublicMemberRestricted()
 {
     $webDAVProject = new WebDAVProjectTestVersion($this);
     $project = new MockProject();
     $project->setReturnValue('isPublic', true);
     $project->setReturnValue('userIsMember', true);
     $webDAVProject->setReturnValue('getProject', $project);
     $utils = new MockWebDAVUtils();
     $webDAVProject->setReturnValue('getUtils', $utils);
     $user = new MockUser();
     $user->setReturnValue('isRestricted', true);
     $webDAVProject->setReturnValue('getUser', $user);
     $this->assertEqual($webDAVProject->userCanRead(), true);
 }
Esempio n. 24
0
 function testSiteAdminCanAlwaysCreate()
 {
     // Setup test
     $frspf = new FRSPackageFactoryTestVersion($this);
     $user = new MockUser($this);
     $user->setReturnValue('isSuperUser', true);
     $um = new MockUserManager($this);
     $um->setReturnValue('getUserById', $user);
     $frspf->setReturnValue('getUserManager', $um);
     $this->assertTrue($frspf->userCanCreate($this->group_id, $this->user_id));
 }
Esempio n. 25
0
 function _PageList_Column_top3recs($params)
 {
     global $request;
     $active_user = $request->getUser();
     if (is_string($active_user)) {
         //FIXME: try to find the bug at test.php which sets request->_user and ->_group
         trigger_error("request->getUser => string: {$active_user}", E_USER_WARNING);
         $active_user = new MockUser($active_user, true);
     }
     // No, I don't know exactly why, but this needs to be a reference for
     // the memoization in pearson_similarity and mean_rating to work
     $this->_active_ratings_user = new RatingsUser($active_user->getId());
     $this->_PageList_Column($params[0], $params[1], $params[2]);
     if (!empty($params[3])) {
         $this->_pagelist =& $params[3];
         $this->_dimension = $this->_pagelist->getOption('dimension');
         $this->_users = $this->_pagelist->getOption('users');
     }
 }
Esempio n. 26
0
 function testUserCanAccessPrivateShouldBlockWhenUserIsNotMemberOfPrivateProject()
 {
     $urlVerification = TestHelper::getPartialMock('URLVerification', array('getProjectManager', 'getCurrentUser'));
     $GLOBALS['group_id'] = 120;
     $project = new MockProject();
     $project->setReturnValue('isError', false);
     $project->setReturnValue('isPublic', false);
     $projectManager = new MockProjectManager();
     $projectManager->setReturnValue('getProject', $project, array(120));
     $urlVerification->setReturnValue('getProjectManager', $projectManager);
     $user = new MockUser();
     $user->setReturnValue('isMember', false);
     $urlVerification->setReturnValue('getCurrentUser', $user);
     $this->assertFalse($urlVerification->userCanAccessPrivate(new MockUrl(), 'stuff'));
 }
Esempio n. 27
0
 private function anAdminUser()
 {
     $adminUser = new MockUser($this);
     $adminUser->setReturnValue('isSuperUser', true);
     return $adminUser;
 }
Esempio n. 28
0
 /**
  * Testing when the user is authenticated as a registered user
  */
 function testAuthenticateSuccessWithNotAnonymousUser()
 {
     $webDAVAuthentication = new WebDAVAuthenticationTestVersion($this);
     $webDAVAuthentication->setReturnValue('issetUsername', true);
     $webDAVAuthentication->setReturnValue('getUsername', 'username');
     $webDAVAuthentication->setReturnValue('getPassword', 'password');
     $user = new MockUser();
     $user->setReturnValue('isAnonymous', false);
     $webDAVAuthentication->setReturnValue('getUser', $user);
     $this->assertEqual($webDAVAuthentication->authenticate(), $user);
 }
Esempio n. 29
0
 private function GivenAUserWithProjects()
 {
     $user = new MockUser();
     $user->setReturnValue('getAllProjects', array('123', '456'));
     $user->setReturnValue('isMember', true, array('123', 'A'));
     $user->setReturnValue('isMember', false, array('456', 'A'));
     return $user;
 }
Esempio n. 30
0
 function testUgroupCountProjectAdminsMixed()
 {
     $this->skipUnless(MOCKFUNCTION_AVAILABLE, "Function mocking not available");
     if (MOCKFUNCTION_AVAILABLE) {
         MockFunction::setReturnValueAt(0, 'db_fetch_array', array('user_id' => 1));
         MockFunction::setReturnValueAt(1, 'db_fetch_array', array('user_id' => 2));
         MockFunction::setReturnValueAt(2, 'db_fetch_array', null);
         MockFunction::expectCallCount('db_fetch_array', 3);
         $user = new MockUser();
         $user->setReturnValueAt(0, 'isMember', true);
         $user->setReturnValueAt(1, 'isMember', false);
         $user->expectCallCount('isMeMber', 2);
         $um = new MockUserManager();
         $um->setReturnValue('getUserById', $user);
         MockFunction::setReturnValue('ugroup_get_user_manager', $um);
         $result = ugroup_count_project_admins(1, '');
         $this->assertEqual(1, $result['admins']);
         $this->assertEqual(1, $result['non_admins']);
     }
 }