function testUpdateSVNAccess() { $project = new MockProject($this); $project->setReturnValue('getUnixNameMixedCase', 'TestProj'); $project->setReturnValue('getSVNRootPath', $GLOBALS['svn_prefix'] . '/TestProj'); $project->setReturnValue('isSVNTracked', true); $proj_members = array("0" => array("user_name" => "user1", "user_id" => "1"), "1" => array("user_name" => "user2", "user_id" => "2"), "2" => array("user_name" => "user3", "user_id" => "3")); $project->setReturnValue('getMembersUserNames', $proj_members); $pm = new MockProjectManager(); $pm->setReturnReference('getProject', $project, array(142)); $ugroups = array("0" => array("name" => "QA", "ugroup_id" => "104"), "1" => array("name" => "Customers", "ugroup_id" => "102")); $ugdao = new MockUGroupDao(); $ugdao->setReturnValue('searchByGroupId', $ugroups); $ugroup = new MockProjectUGroup($this); $ugroup->setReturnValueAt(0, 'getMembersUserName', array('user1', 'user2', 'user3')); $ugroup->setReturnValueAt(1, 'getMembersUserName', array('user1', 'user4')); $ugroup->setReturnValueAt(2, 'getMembersUserName', array('user1', 'user2', 'user3')); $ugroup->setReturnValueAt(3, 'getMembersUserName', array('user1', 'user4')); $ugroup->setReturnValueAt(4, 'getMembersUserName', array('user1', 'user2', 'user3')); $ugroup->setReturnValueAt(5, 'getMembersUserName', array('user1', 'user4', 'user5')); $ugroup->setReturnValueAt(0, 'getName', "QA"); $ugroup->setReturnValueAt(1, 'getName', "QA"); $ugroup->setReturnValueAt(4, 'getName', "QA"); $ugroup->setReturnValueAt(5, 'getName', "QA"); $ugroup->setReturnValueAt(8, 'getName', "QA"); $ugroup->setReturnValueAt(9, 'getName', "QA"); $ugroup->setReturnValueAt(2, 'getName', "customers"); $ugroup->setReturnValueAt(3, 'getName', "customers"); $ugroup->setReturnValueAt(6, 'getName', "customers"); $ugroup->setReturnValueAt(7, 'getName', "customers"); $ugroup->setReturnValueAt(10, 'getName', "customers"); $ugroup->setReturnValueAt(11, 'getName', "customers"); $backend = new BackendSVNTestVersion($this); $backend->setReturnValue('getProjectManager', $pm); $backend->setReturnValue('getUGroupFromRow', $ugroup); $backend->setReturnValue('getUGroupDao', $ugdao); $this->assertEqual($backend->createProjectSVN(142), True); $this->assertTrue(is_dir($GLOBALS['svn_prefix'] . "/TestProj"), "SVN dir should be created"); $this->assertTrue(is_file($GLOBALS['svn_prefix'] . "/TestProj/.SVNAccessFile"), "SVN access file should be created"); $saf = new MockSVNAccessFile(); $backend->setReturnValue('_getSVNAccessFile', $saf); // Update without modification $this->assertEqual($backend->updateSVNAccess(142), True); $this->assertTrue(is_file($GLOBALS['svn_prefix'] . "/TestProj/.SVNAccessFile"), "SVN access file should exist"); $this->assertTrue(is_file($GLOBALS['svn_prefix'] . "/TestProj/.SVNAccessFile.new"), "SVN access file (.new) should be created"); $this->assertFalse(is_file($GLOBALS['svn_prefix'] . "/TestProj/.SVNAccessFile.old"), "SVN access file (.old) should not be created"); // Update with modification $this->assertEqual($backend->updateSVNAccess(142), True); $this->assertFalse(is_file($GLOBALS['svn_prefix'] . "/TestProj/.SVNAccessFile.new"), "SVN access file (.new) should be removed"); $this->assertTrue(is_file($GLOBALS['svn_prefix'] . "/TestProj/.SVNAccessFile.old"), "SVN access file (.old) should be created"); // Cleanup $backend->recurseDeleteInDir($GLOBALS['svn_prefix'] . "/TestProj"); rmdir($GLOBALS['svn_prefix'] . "/TestProj"); }
public function itverifiesUserGroupMembersAreProjectMembersWhenProjectIsPrivate() { $user1 = mock('PFUser'); $user1->setReturnValue('getUserName', 'user1'); $user2 = mock('PFUser'); $user2->setReturnValue('getUserName', 'user2'); $project = new MockProject($this); $project->setReturnValue('getMembers', array($user2)); $project->setReturnValue('isPublic', false); $usergroup_dao = new MockUGroupDao(); $usergroup_dao->setReturnValue('searchByGroupId', array(array('name' => 'Perms'))); $this->backend->setReturnValue('getUGroupDao', $usergroup_dao); $ugroup = new MockProjectUGroup($this); $ugroup->setReturnValue('getMembers', array($user1, $user2)); $ugroup->setReturnValue('getName', 'Perms'); $this->backend->setReturnValue('getUGroupFromRow', $ugroup); $ugroup_members_line = $this->backend->getSVNAccessUserGroupMembers($project); $this->assertEqual($ugroup_members_line, "Perms = user2\n\n"); }
function testUgroupCountNonAdminForStaticUgroupsMixed() { $this->skipUnless(MOCKFUNCTION_AVAILABLE, "Function mocking not available"); if (MOCKFUNCTION_AVAILABLE) { $uGroup = new MockProjectUGroup(); $uGroup->setReturnValue('exists', true, array(1, 1)); $uGroup->setReturnValue('exists', true, array(1, 2)); $uGroup->setReturnValue('exists', true, array(1, 3)); $uGroup->setReturnValue('exists', true, array(1, 4)); MockFunction::generate('ugroup_get_ugroup'); MockFunction::setReturnValue('ugroup_get_ugroup', $uGroup); MockFunction::generate('ugroup_count_project_admins'); MockFunction::setReturnValueAt(0, 'ugroup_count_project_admins', array('admins' => 0, 'non_admins' => 2)); MockFunction::setReturnValueAt(1, 'ugroup_count_project_admins', array('admins' => 1, 'non_admins' => 3)); MockFunction::expectCallCount('ugroup_count_project_admins', 2); $validUGroups = array(1, 2); $this->assertEqual(3, ugroup_count_non_admin_for_static_ugroups(1, array(3, 4), $validUGroups)); $this->assertEqual(array(1, 2, 4), $validUGroups); MockFunction::restore('ugroup_count_project_admins'); } }