/** * Check to see if the specification is satisfied * * @param $name * @return bool */ public function isSatisfiedBy($name) { if (!$this->repository->groupOfName($name)) { return true; } return false; }
/** @test */ public function should_find_group() { $group = m::mock('Cribbb\\Domain\\Model\\Groups\\Group'); $this->groups->shouldReceive('groupBySlug')->once()->andReturn($group); $group = $this->service->find('cribbb'); $this->assertInstanceOf('Cribbb\\Domain\\Model\\Groups\\Group', $group); }
/** @test */ public function should_create_new_group() { $user = m::mock('Cribbb\\Domain\\Model\\Identity\\User'); $this->users->shouldReceive('userById')->once()->andReturn($user); $this->groups->shouldReceive('groupOfName')->once()->andReturn(null); $this->groups->shouldReceive('add')->once(); $group = $this->service->create('7c5e8127-3f77-496c-9bb4-5cb092969d89', 'Cribbb'); $this->assertInstanceOf('Cribbb\\Domain\\Model\\Groups\\Group', $group); }
/** @test */ public function should_allow_user_to_join_the_group() { $user = m::mock('Cribbb\\Domain\\Model\\Identity\\User'); $group = m::mock('Cribbb\\Domain\\Model\\Groups\\Group'); $group->shouldReceive('addMember')->once(); $this->users->shouldReceive('userById')->once()->andReturn($user); $this->groups->shouldReceive('groupById')->once()->andReturn($group); $group = $this->service->join('7c5e8127-3f77-496c-9bb4-5cb092969d89', 'a3d9e532-0ea8-4572-8e83-119fc49e4c6f'); $this->assertInstanceOf('Cribbb\\Domain\\Model\\Groups\\Group', $group); }
/** @test */ public function should_create_new_thread() { $user = m::mock('Cribbb\\Domain\\Model\\Identity\\User'); $group = m::mock('Cribbb\\Domain\\Model\\Groups\\Group'); $thread = m::mock('Cribbb\\Domain\\Model\\Discussion\\Thread'); $this->users->shouldReceive('userById')->once()->andReturn($user); $this->groups->shouldReceive('groupById')->once()->andReturn($group); $group->shouldReceive('startNewThread')->once()->andReturn($thread); $this->threads->shouldReceive('add')->once(); $thread = $this->service->create('7c5e8127-3f77-496c-9bb4-5cb092969d89', 'a3d9e532-0ea8-4572-8e83-119fc49e4c6f', 'Hello World'); $this->assertInstanceOf('Cribbb\\Domain\\Model\\Discussion\\Thread', $thread); }
private function recursiveObjectives($objectives, $parent, $structure) { foreach ($objectives as $obj) { $data = $obj; //$data['parent'] = $parent; $objective = $this->currRepo->objectiveOfCode($data['code']); //if not already exists in database if (!$objective) { $objective = Objective::register(new Name($data['name']), $data['code'], $structure); if ($parent) { $parent->addChild($objective); $objective->setParent($parent); } $this->manager->persist($objective); $structure->addObjective($objective); if (isset($data['level'])) { $o_levels = str_split($data['level']); //find group $i = 0; foreach ($this->cur_classlevels as $grouplevel) { $group = $this->groupRepo->groupOfName($grouplevel); $obj_level = ObjectiveControlLevel::register($group, $objective, $o_levels[$i++]); $this->manager->merge($obj_level); } } } if (isset($data['obj'])) { $this->recursiveObjectives($data['obj'], $objective, $structure); } } //$this->manager->persist($structure); if ($parent) { $this->manager->persist($parent); } }
/** * @return array|int[] */ protected function GetGroupRoles() { $groupId = $this->page->GetGroupId(); $group = $this->groupRepository->LoadById($groupId); $ids = $group->RoleIds(); return $ids; }
public function LoadById($groupId) { $user = $this->userRepository->LoadById($this->userSession->UserId); if ($user->IsGroupAdminFor($groupId)) { return parent::LoadById($groupId); } return Group::Null(); }
public function testCanGetListOfGroupsByRole() { $roleLevel = RoleLevel::GROUP_ADMIN; $groupItemRow = new GroupItemRow(); $groupItemRow->With(1, 'g1')->With(2, 'g2'); $rows = $groupItemRow->Rows(); $this->db->SetRow(0, $rows); $getGroupsCommand = new GetAllGroupsByRoleCommand($roleLevel); $groups = $this->repository->GetGroupsByRole($roleLevel); $this->assertEquals(GroupItemView::Create($rows[0]), $groups[0]); $this->assertEquals(GroupItemView::Create($rows[1]), $groups[1]); $this->assertTrue($this->db->ContainsCommand($getGroupsCommand), "missing select group command"); }
private function MigrateGroups(Database $legacyDatabase, Database $currentDatabase) { $groupsMigrated = MigrationSession::GetLastGroupRow(); Log::Debug('Start migrating groups. Starting at row %s', $groupsMigrated); $groupRepo = new GroupRepository(); $getExisting = new AdHocCommand('select legacyid from groups'); $reader = $currentDatabase->Query($getExisting); $knownIds = array(); while ($row = $reader->GetRow()) { $knownIds[] = $row['legacyid']; } $getGroups = new AdHocCommand("select groupid, group_name from groups order by groupid limit {$groupsMigrated}, 500"); $reader = $legacyDatabase->Query($getGroups); while ($row = $reader->GetRow()) { if (in_array($row['groupid'], $knownIds)) { continue; } $newId = $groupRepo->Add(new Group(null, $row['group_name'])); $currentDatabase->Execute(new AdHocCommand("update groups set legacyid = \"{$row['groupid']}\" where group_id = {$newId}")); $groupsMigrated++; MigrationSession::SetLastGroupRow($groupsMigrated); } Log::Debug('Done migrating groups (%s groups)', $groupsMigrated); $getLegacyCount = new AdHocCommand('select count(*) as count from groups'); $getMigratedCount = new AdHocCommand('select count(*) as count from groups where legacyid is not null'); $progressCounts = $this->GetProgressCounts($getLegacyCount, $getMigratedCount); $this->page->SetProgress($progressCounts); $this->page->SetGroupsMigrated($progressCounts->MigratedCount); MigrationSession::SetLastGroupRow($progressCounts->MigratedCount); }
private function GetGroupUsers($groupId) { $groupRepo = new GroupRepository(); $results = $groupRepo->GetUsersInGroup($groupId)->Results(); /** @var $result UserItemView */ foreach ($results as $result) { // consolidates results by user id if the user is in multiple groups $users[$result->Id] = new AutocompleteUser($result->Id, $result->First, $result->Last, $result->Email, $result->Username); } return array_values($users); }
/** @test */ public function should_return_false_when_not_unique() { $this->repository->shouldReceive('groupOfName')->andReturn(['id' => 1]); $this->assertFalse($this->spec->isSatisfiedBy('Cribbb')); }
/** * @return array */ public function getGroupsForUser($user) { return $this->repository->findAllForUser($user); }