public function itBuildsAnEmptyFreestyleCollectionIfThereIsNothingInTheDaoAndNoStatus() { stub($this->tracker)->getStatusField()->returns(null); stub($this->dao)->searchColumnsByTrackerId(42)->returns(TestHelper::arrayToDar()); $columns = $this->factory->getDashboardColumns($this->tracker, $this->swimline_tracker); $this->assertIsA($columns, 'Cardwall_OnTop_Config_ColumnFreestyleCollection'); $this->assertEqual(0, count($columns)); }
private function GivenThereWasAlreadyTenCallToAddProject() { $dao = new MockSOAP_RequestLimitatorDao(); $time30minutesAgo = $_SERVER['REQUEST_TIME'] - 30 * 60; $dar = TestHelper::arrayToDar(array('method_name' => 'addProject', 'date' => $time30minutesAgo)); $dao->setReturnValue('searchFirstCallToMethod', $dar); $dao->setReturnValue('foundRows', 10); $dao->expectOnce('saveCallToMethod', array('addProject', '*')); return $dao; }
private function GivenAFullApacheConf() { $backend = TestHelper::getPartialMock('LDAP_BackendSVN', array('_getServiceDao', 'getLdap', 'getLDAPProjectManager', 'getSVNApacheAuthFactory')); $dar = TestHelper::arrayToDar(array('unix_group_name' => 'gpig', 'group_name' => 'Guinea Pig', 'group_id' => 101), array('unix_group_name' => 'garden', 'group_name' => 'The Garden Project', 'group_id' => 102)); $dao = new MockServiceDao(); $dao->setReturnValue('searchActiveUnixGroupByUsedService', $dar); $backend->setReturnValue('_getServiceDao', $dao); $factory = TestHelper::getPartialMock('SVN_Apache_Auth_Factory', array('getEventManager')); $factory->setReturnValue('getEventManager', new LDAP_BackendSVNTestEventManager()); $backend->setReturnValue('getSVNApacheAuthFactory', $factory); return $backend->getApacheConf(); }
public function itCatchExceptionsInSystemEvents() { $system_event = partial_mock('SysteEvent_For_Testing_Purpose', array('process', 'notify', 'verbalizeParameters')); $types = array('some_type'); stub($this->system_event_manager)->getTypesForQueue()->returns($types); $this->system_event_dao->setReturnValueAt(0, 'checkOutNextEvent', TestHelper::arrayToDar(array('whatever'))); stub($this->system_event_manager)->getInstanceFromRow()->returns($system_event); $system_event->throwOn('process', new RuntimeException('Something wrong happened')); $category = SystemEvent::DEFAULT_QUEUE; $this->processor->execute($category); $this->assertEqual($system_event->getStatus(), SystemEvent::STATUS_ERROR); $this->assertEqual($system_event->getLog(), 'Something wrong happened'); }
function testGetWithChildren() { $tracker = aTracker()->withId(1)->build(); $dao = new MockTracker_Hierarchy_Dao(); $children_ids = TestHelper::arrayToDar(array('parent_id' => 1, 'child_id' => 2), array('parent_id' => 1, 'child_id' => 3)); $dao->setReturnValue('getChildren', $children_ids, array($tracker->getId())); $child1 = aTracker()->withId(2)->build(); $child2 = aTracker()->withId(3)->build(); $tracker_factory = new MockTrackerFactory(); $tracker_factory->setReturnValue('getTrackerById', $child1, array(2)); $tracker_factory->setReturnValue('getTrackerById', $child2, array(3)); $factory = new Tracker_Hierarchy_HierarchicalTrackerFactory($tracker_factory, $dao); $hierarchical_tracker = $factory->getWithChildren($tracker); $children = $hierarchical_tracker->getChildren(); $children = $this->assertChildEquals($children, $child1); $children = $this->assertChildEquals($children, $child2); $this->assertEqual(count($children), 0); }
private function GivenAFullApacheConf() { $backend = TestHelper::getPartialMock('LDAP_BackendSVN', array('_getServiceDao', 'getLdap', 'getLDAPProjectManager', 'getSVNApacheAuthFactory')); $project_array_01 = array('unix_group_name' => 'gpig', 'group_name' => 'Guinea Pig', 'group_id' => 101); $project_array_02 = array('unix_group_name' => 'garden', 'group_name' => 'The Garden Project', 'group_id' => 102); $dar = TestHelper::arrayToDar($project_array_01, $project_array_02); $dao = new MockServiceDao(); $dao->setReturnValue('searchActiveUnixGroupByUsedService', $dar); $backend->setReturnValue('_getServiceDao', $dao); $ldap = mock('LDAP'); stub($ldap)->getLDAPParam('server')->returns('ldap://ldap.tuleap.com'); stub($ldap)->getLDAPParam('dn')->returns('dc=tuleap,dc=com'); $project_manager = mock('ProjectManager'); $event_manager = new LDAP_BackendSVNTestEventManager(); $token_manager = mock('SVN_TokenUsageManager'); $factory = new SVN_Apache_Auth_Factory($project_manager, $event_manager, $token_manager); $backend->setReturnValue('getSVNApacheAuthFactory', $factory); return $backend->getApacheConf(); }
public function setUp() { $element_factory = mock('Tracker_FormElementFactory'); $this->dao = mock('Cardwall_OnTop_ColumnMappingFieldValueDao'); $column_factory = mock('Cardwall_OnTop_Config_ColumnFactory'); $this->factory = new Cardwall_OnTop_Config_ValueMappingFactory($element_factory, $this->dao); $this->field_123 = aMockField()->withId(123)->build(); $this->field_124 = aMockField()->withId(124)->build(); $this->status_field = aMockField()->withId(125)->build(); stub($this->field_124)->getListValueById(1001)->returns(stub('Tracker_FormElement_Field_List_Value')->getId()->returns(1001)); stub($this->field_124)->getListValueById(1002)->returns(stub('Tracker_FormElement_Field_List_Value')->getId()->returns(1002)); stub($this->status_field)->getListValueById(1000)->returns(stub('Tracker_FormElement_Field_List_Value')->getId()->returns(1000)); stub($element_factory)->getFieldById(123)->returns($this->field_123); stub($element_factory)->getFieldById(124)->returns($this->field_124); stub($element_factory)->getFieldById(125)->returns($this->status_field); $group_id = 234; $this->tracker = aMockTracker()->withId(3)->withProjectId($group_id)->build(); $this->tracker_10 = aMockTracker()->withId(10)->withStatusField($this->status_field)->build(); $this->tracker_20 = aMockTracker()->withId(20)->build(); stub($this->dao)->searchMappingFieldValues($this->tracker->getId())->returns(TestHelper::arrayToDar(array('tracker_id' => 10, 'field_id' => 125, 'value_id' => 1000, 'column_id' => 1), array('tracker_id' => 20, 'field_id' => 124, 'value_id' => 1001, 'column_id' => 1), array('tracker_id' => 20, 'field_id' => 124, 'value_id' => 1002, 'column_id' => 2))); stub($this->status_field)->getVisibleValuesPlusNoneIfAny()->returns(array(new Tracker_FormElement_Field_List_Bind_StaticValue(1001, 'Todo', '', 0, 0), new Tracker_FormElement_Field_List_Bind_StaticValue(1002, 'On Going', '', 0, 0), new Tracker_FormElement_Field_List_Bind_StaticValue(1003, 'Done', '', 0, 0))); }
public function itIsNeitherRestrictedNorActive() { $this->user_stub->getStatus()->returns('Not exists'); $this->user_stub->getProjects()->returns(array()); $this->user_stub->isMember()->returns(false); $this->user_stub->getAllUgroups()->returns(TestHelper::arrayToDar()); $groups = $this->ugroup_literalizer->getUserGroupsForUserName('john_do'); $this->assertEqual(array(), $groups); }
function itIsNotPossibleToRemoveAllAdminsOfAProject() { $ugroup_id = $GLOBALS['UGROUP_PROJECT_ADMIN']; $group_id = 300; $ugroup = TestHelper::getPartialMock('UGroup', array('_getUserGroupDao')); $project_admin_dar = TestHelper::arrayToDar(array('LastAdmin')); $dao = stub('UserGroupDao')->returnProjectAdminsByGroupId($group_id)->returns($project_admin_dar); stub($ugroup)->_getUserGroupDao()->returns($dao); $ugroup->__construct(array('ugroup_id' => $ugroup_id, 'group_id' => $group_id)); $dao->expectNever('updateUserGroupFlags'); $this->expectException(); $ugroup->removeUser($this->user); }
public function testGetFieldFromTrackerAndSharedField() { $original_field_dar = TestHelper::arrayToDar($this->createRow(999, 'text')); $dao = new MockTracker_FormElement_FieldDao(); $dao->setReturnValue('searchFieldFromTrackerIdAndSharedFieldId', $original_field_dar, array(66, 123)); $factory = $this->GivenAFormElementFactory(); $factory->setReturnValue('getDao', $dao); $originalField = aTextField()->withId(999)->build(); $tracker = aTracker()->withId(66)->build(); $exportedField = aTextField()->withId(123)->build(); $this->assertEqual($factory->getFieldFromTrackerAndSharedField($tracker, $exportedField), $originalField); }
public function itReturnsNothingIfThereIsNoAssociatedPlanning() { $tracker = aMockTracker()->withId(99)->build(); $empty_dar = TestHelper::arrayToDar(); $dao = stub('PlanningDao')->searchByPlanningTrackerId()->returns($empty_dar); $factory = aPlanningFactory()->withDao($dao)->build(); $this->assertNull($factory->getPlanningByPlanningTracker($tracker)); }
public function itLoadValueMappingsEvenForStatusField() { stub($this->dao)->searchMappingFields($this->tracker->getId())->returns(TestHelper::arrayToDar(array('tracker_id' => 10, 'field_id' => null))); stub($this->value_mapping_factory)->getStatusMappings($this->tracker_10, $this->columns)->once(); $this->factory->getMappings($this->tracker, $this->columns); }
public function itReturnOnlyPlanningsWhereTheUserCanViewTrackers() { $tracker1 = new MockTracker(); stub($tracker1)->userCanView($this->user)->returns(true); $tracker2 = new MockTracker(); stub($tracker2)->userCanView($this->user)->returns(false); $factoryBuilder = aPlanningFactory(); $factoryBuilder->tracker_factory->setReturnValue('getTrackerById', $tracker1, array(103)); $factoryBuilder->tracker_factory->setReturnValue('getTrackerById', $tracker2, array(104)); $result_set = TestHelper::arrayToDar(array('id' => 1, 'name' => 'Release Backlog', 'group_id' => 102, 'planning_tracker_id' => 103, 'backlog_title' => 'Release Backlog', 'plan_title' => 'Sprint Plan'), array('id' => 2, 'name' => 'Product Backlog', 'group_id' => 102, 'planning_tracker_id' => 104, 'backlog_title' => 'Release Backlog', 'plan_title' => 'Sprint Plan')); $factoryBuilder->dao->setReturnValue('searchPlannings', $result_set); $expected = array(new Planning(1, 'Release Backlog', 102, 'Release Backlog', 'Sprint Plan')); $this->assertEqual($expected, $factoryBuilder->build()->getPlannings($this->user, 123)); }
function testGetProjectRepositoryListShouldReturnProjectRepositories() { $projectId = 42; $userId = 24; $project_repos = array(array('id' => '1', 'name' => 'a'), array('id' => '2', 'name' => 'b')); $sandra_repos = array(array('id' => '3', 'name' => 'c')); $repo_owners = TestHelper::arrayToDar(array(array('id' => '123'), array('id' => '456'))); $dao = new MockGitDao(); $dao->setReturnValue('getProjectRepositoryList', $project_repos, array($projectId, false, true, null)); $dao->setReturnValue('getProjectRepositoryList', $sandra_repos, array($projectId, false, true, $userId)); $dao->setReturnValue('getProjectRepositoriesOwners', $repo_owners, array($projectId)); $controller = new MockGit(); $controller->expectAt(0, 'addData', array(array('repository_list' => $project_repos, 'repositories_owners' => $repo_owners))); $controller->expectAt(1, 'addData', array(array('repository_list' => $sandra_repos, 'repositories_owners' => $repo_owners))); $action = TestHelper::getPartialMock('GitActions', array('getDao')); $action->setController($controller); $action->setReturnValue('getDao', $dao); $action->getProjectRepositoryList($projectId); $action->getProjectRepositoryList($projectId, $userId); }
public function itProvidesTheUserNames() { $dar = TestHelper::arrayToDar(aUser()->withUserName('Nicolas')->build(), aUser()->withUserName('Johan')->build()); $users = new Users($dar); $this->assertEqual($users->getNames(), array('Nicolas', 'Johan')); }
public function itDoesntRemoveTheGerritReservedKeys() { $this->user_manager->setReturnValueAt(0, 'getUsersWithSshKey', TestHelper::arrayToDar(new PFUser(array('authorized_keys' => $this->key1, 'user_name' => 'john_do')))); $this->mass_dumper->dumpSSHKeys(); $keyfile = '*****@*****.**'; touch($this->_glAdmDir . '/keydir/' . $keyfile); $this->gitExec->add($this->_glAdmDir . '/keydir/' . $keyfile); $this->gitExec->commit("Gerrit key"); $this->assertEmptyGitStatus(); $this->user_manager->setReturnValueAt(1, 'getUsersWithSshKey', TestHelper::emptyDar()); $this->mass_dumper->dumpSSHKeys(); $this->assertFalse(is_file($this->_glAdmDir . '/keydir/john_do@0.pub')); $this->assertTrue(is_file($this->_glAdmDir . '/keydir/' . $keyfile)); }
private function getResultsForTrackerOutsideHierarchy() { return TestHelper::arrayToDar(array('id' => 66, 'tracker_id' => 666, 'artifactlinks' => ''), array('id' => 8, 'tracker_id' => 111, 'artifactlinks' => '11,9,34'), array('id' => 11, 'tracker_id' => 113, 'artifactlinks' => ''), array('id' => 7, 'tracker_id' => 112, 'artifactlinks' => '5'), array('id' => 6, 'tracker_id' => 112, 'artifactlinks' => '8'), array('id' => 5, 'tracker_id' => 111, 'artifactlinks' => ''), array('id' => 9, 'tracker_id' => 113, 'artifactlinks' => ''), array('id' => 10, 'tracker_id' => 113, 'artifactlinks' => '66')); }
public function setUp() { parent::setUp(); stub($this->dao)->searchMappingFields($this->tracker_id)->returns(TestHelper::arrayToDar(array('cardwall_tracker_id' => 666, 'tracker_id' => 69, 'field_id' => 321))); $existing_mappings = array(42 => new Cardwall_OnTop_Config_TrackerMappingStatus($this->task_tracker, array(), array(), $this->status_field), 69 => new Cardwall_OnTop_Config_TrackerMappingFreestyle($this->story_tracker, array(), array(9001 => new Cardwall_OnTop_Config_ValueMapping(aFieldListStaticValue()->withId(9001)->build(), 11), 9002 => new Cardwall_OnTop_Config_ValueMapping(aFieldListStaticValue()->withId(9002)->build(), 11), 9007 => new Cardwall_OnTop_Config_ValueMapping(aFieldListStaticValue()->withId(9002)->build(), 12)), $this->stage_field)); $this->command = new Cardwall_OnTop_Config_Command_UpdateMappingFields($this->tracker, $this->dao, $this->value_dao, $this->tracker_factory, $this->element_factory, $existing_mappings); }
function testGetAllProjectShouldListOnlyOneOccurenceOfEachProject() { $user = TestHelper::getPartialMock('User', array('getProjects', 'getUGroupDao')); $user->setReturnValue('getProjects', array(101, 103)); $dar = TestHelper::arrayToDar(array('group_id' => 102), array('group_id' => 103), array('group_id' => 104)); $dao = new MockUGroupDao(); $dao->setReturnValue('searchGroupByUserId', $dar); $user->setReturnValue('getUGroupDao', $dao); $this->assertEqual(array(102, 103, 104, 101), $user->getAllProjects()); }
private function GivenADaoThatContainsFullHierarchy() { $dao = new MockTracker_Hierarchy_Dao(); $dar1 = TestHelper::arrayToDar(array('parent_id' => 111, 'child_id' => 112), array('parent_id' => 113, 'child_id' => 114)); $dao->setReturnValue('searchTrackerHierarchy', $dar1, array(array(111, 114))); $dar2 = TestHelper::arrayToDar(array('parent_id' => 111, 'child_id' => 112), array('parent_id' => 112, 'child_id' => 113), array('parent_id' => 113, 'child_id' => 114)); $dao->setReturnValue('searchTrackerHierarchy', $dar2, array(array(112, 113))); return $dao; }