public function testExecutes_ForkCrossProject_ActionWithForkRepositoriesView() { $groupId = 101; $toProjectId = 100; $toProject = new MockProject(); $toProject->setReturnValue('getId', $toProjectId); $repo = new GitRepository(); $repos = array($repo); $repo_ids = array(200); $user = new MockUser(); $user->setReturnValue('isMember', true); $usermanager = new MockUserManager(); $usermanager->setReturnValue('getCurrentUser', $user); $projectManager = new MockProjectManager(); $projectManager->setReturnValue('getProject', $toProject, array($toProjectId)); $repositoryFactory = new MockGitRepositoryFactory(); $repositoryFactory->setReturnValue('getRepositoryById', $repo, array($repo_ids[0])); $request = new Codendi_Request(array('choose_destination' => 'project', 'to_project' => $toProjectId, 'repos' => $repo_ids)); $git = TestHelper::getPartialMock('Git', array('definePermittedActions', '_informAboutPendingEvents', 'addAction', 'addView', 'checkSynchronizerToken')); $git->setGroupId($groupId); $git->setRequest($request); $git->setUserManager($usermanager); $git->setProjectManager($projectManager); $git->setFactory($repositoryFactory); $git->expectCallCount('addAction', 2); $git->expectAt(0, 'addAction', array('fork', array($repos, $toProject, '', GitRepository::REPO_SCOPE_PROJECT, $user, $GLOBALS['HTML'], '/plugins/git/?group_id=100'))); $git->expectAt(1, 'addAction', array('getProjectRepositoryList', array($groupId))); $git->expectOnce('addView', array('forkRepositories')); $git->_dispatchActionAndView('do_fork_repositories', null, null, $user); }
function testGetRepositoryFromFullPathAndGitRoot() { $dao = new MockGitDao(); $projectManager = new MockProjectManager(); $project = new MockProject(); $project->setReturnValue('getID', 101); $project->setReturnValue('getUnixName', 'garden'); $projectManager->setReturnValue('getProjectByUnixName', $project, array('garden')); $factory = new GitRepositoryFactory($dao, $projectManager); $dao->expectOnce('searchProjectRepositoryByPath', array(101, 'garden/diskinstaller.git')); $dao->setReturnValue('searchProjectRepositoryByPath', new MockDataAccessResult()); $factory->getFromFullPath('/data/tuleap/gitroot/garden/diskinstaller.git'); }
public function testExecutes_ForkRepositories_ActionWithAListOfRepos() { $groupId = 101; $repo = new GitRepository(); $repos = array($repo); $user = new User(); $user->setId(42); $user->setUserName('Ben'); $path = userRepoPath('Ben', 'toto'); $project = new MockProject(); $projectManager = new MockProjectManager(); $projectManager->setReturnValue('getProject', $project, array($groupId)); $factory = new MockGitRepositoryFactory(); $factory->setReturnValue('getRepositoryById', $repo); $git = TestHelper::getPartialMock('Git', array('definePermittedActions', '_informAboutPendingEvents', 'addAction', 'addView', 'checkSynchronizerToken')); $git->setGroupId($groupId); $git->setProjectManager($projectManager); $git->expectAt(0, 'addAction', array('getProjectRepositoryList', array($groupId))); $git->expectAt(1, 'addAction', array('fork', array($repos, $project, $path, GitRepository::REPO_SCOPE_INDIVIDUAL, $user, $GLOBALS['HTML'], '/plugins/git/?group_id=101&user=42'))); $request = new Codendi_Request(array('repos' => array('1001'), 'path' => 'toto')); $git->setFactory($factory); $git->_doDispatchForkRepositories($request, $user); }
function testValidNamesAreValid() { $um = new MockUserManager($this); $um->setReturnValue('getUserByUserName', null); $pm = new MockProjectManager($this); $pm->setReturnValue('getProjectByUnixName', null); $backend = new MockBackend($this); $backend->setReturnValue('unixUserExists', false); $backend->setReturnValue('unixGroupExists', false); $sm = new MockSystemEventManager($this); $sm->setReturnValue('isUserNameAvailable', true); $sm->setReturnValue('isProjectNameAvailable', true); $r = new Rule_ProjectNameIntegration($this); $r->setReturnValue('_getUserManager', $um); $r->setReturnValue('_getProjectManager', $pm); $r->setReturnValue('_getBackend', $backend); $r->setReturnValue('_getSystemEventManager', $sm); $r->setReturnValue('isNameAvailable', true, array("group-test")); $r->setReturnValue('isNameAvailable', true, array("test")); $r->setReturnValue('isNameAvailable', true, array("test1")); $this->assertTrue($r->isValid("group-test")); $this->assertTrue($r->isValid("test")); $this->assertTrue($r->isValid("test1")); }
function testUserCanAccessPrivateShouldLetUserPassWhenProjectIsPublic() { $urlVerification = TestHelper::getPartialMock('URLVerification', array('getProjectManager', 'exitError', 'displayRestrictedUserError', 'displayPrivateProjectError')); $GLOBALS['group_id'] = 120; $project = new MockProject(); $project->setReturnValue('isError', false); $project->setReturnValue('isActive', true); $project->setReturnValue('isPublic', true); $projectManager = new MockProjectManager(); $projectManager->setReturnValue('getProject', $project); $urlVerification->setReturnValue('getProjectManager', $projectManager); $urlVerification->expectNever('exitError'); $urlVerification->expectNever('displayRestrictedUserError'); $urlVerification->expectNever('displayPrivateProjectError'); $urlVerification->assertValidUrl(array('SCRIPT_NAME' => '/stuff', 'REQUEST_URI' => '/stuff')); }
function testProjectNameExists() { $p = new MockProject($this); $pm = new MockProjectManager($this); $pm->setReturnValue('getProjectByUnixName', $p, array("usertest")); $r = new Rule_UserNameTestVersion($this); $r->setReturnValue('_getProjectManager', $pm); $this->assertTrue($r->isAlreadyProjectName("usertest")); }
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')); }
private function GivenAProjectManager($project) { $manager = new MockProjectManager(); $manager->setReturnValue('getProject', $project, array($project->getId())); return $manager; }
function testUpdateCVSWatchModeNotifyExist() { $project = new MockProject($this); $project->setReturnValue('getUnixName', 'TestProj', array(false)); $pm = new MockProjectManager(); $pm->setReturnValue('getProject', $project, array(1)); $project->setReturnValue('getMembersUserNames', array()); $backend = new BackendCVSTestVersion($this); $backend->setReturnValue('getProjectManager', $pm); $backend->setReturnValue('getCVSWatchMode', false); // Simulate notify generated using command $cvsdir = $GLOBALS['cvs_prefix'] . '/TestProj'; mkdir($cvsdir); system($GLOBALS['cvs_cmd'] . " -d {$cvsdir} init"); $this->assertTrue($backend->updateCVSWatchMode(1)); // Cleanup $backend->recurseDeleteInDir($GLOBALS['cvs_prefix'] . "/TestProj"); rmdir($GLOBALS['cvs_prefix'] . "/TestProj"); }
function testGetProjectWithNeitherProjectNorGroupID() { $r = new FRSReleaseTestVersion($this); $r->setPackageId(696); $pkg = new FRSPackage(array('group_id' => 123)); $pf = new MockFRSPackageFactory($this); $pf->expectOnce('getFRSPackageFromDb', array(696, null, FRSPackageDao::INCLUDE_DELETED)); $pf->setReturnValue('getFRSPackageFromDb', $pkg); $r->setReturnValue('_getFRSPackageFactory', $pf); $p = new MockProject($this); $pm = new MockProjectManager($this); $pm->expectOnce('getProject', array(123)); $pm->setReturnValue('getProject', $p); $r->setReturnValue('_getProjectManager', $pm); $this->assertIdentical($p, $r->getProject()); }