public function testOnlyGetsPageableResourcesWhereUserIsAdmin()
 {
     $pageNum = 10;
     $pageSize = 100;
     $existingFilter = new SqlFilterEquals('a', 'b');
     $groups = array(new UserGroup(1, 'g1', null, RoleLevel::SCHEDULE_ADMIN), new UserGroup(2, 'g2', null, RoleLevel::RESOURCE_ADMIN));
     $scheduleAdminGroupIds = array(1);
     $resourceAdminGroupIds = array(2);
     $this->userRepository->expects($this->once())->method('LoadGroups')->with($this->equalTo($this->fakeUser->UserId), $this->equalTo(array(RoleLevel::SCHEDULE_ADMIN, RoleLevel::RESOURCE_ADMIN)))->will($this->returnValue($groups));
     $repo = new ResourceAdminResourceRepository($this->userRepository, $this->fakeUser);
     $repo->GetList($pageNum, $pageSize, null, null, $existingFilter);
     $additionalFilter = new SqlFilterIn(new SqlFilterColumn(TableNames::SCHEDULES_ALIAS, ColumnNames::SCHEDULE_ADMIN_GROUP_ID), $scheduleAdminGroupIds);
     $expectedFilter = $existingFilter->_And($additionalFilter->_Or(new SqlFilterIn(ColumnNames::RESOURCE_ADMIN_GROUP_ID, $resourceAdminGroupIds)));
     $expectedCommand = new FilterCommand(new GetAllResourcesCommand(), $expectedFilter);
     $lastCommand = $this->db->_LastCommand;
     $this->assertEquals($expectedCommand->GetQuery(), $lastCommand->GetQuery());
 }
Пример #2
0
 public function testGetGroupReservations()
 {
     $command = new GetFullGroupReservationListCommand(array(1, 2));
     $filterCommand = new FilterCommand($command, new SqlFilterEquals(ColumnNames::ACCESSORY_NAME, 'something just to make sure filter does not break subquery'));
     $countCommand = new CountCommand($filterCommand);
     $containsSubQuery = $this->stringContains("INNER JOIN (SELECT user_id FROM user_groups WHERE group_id IN (@groupid)) ss on ss.user_id = owner_id WHERE ", false);
     $containsFilter = $this->stringContains("AND (accessory_name = @accessory_name)", false);
     $query = $filterCommand->GetQuery();
     $countQuery = $countCommand->GetQuery();
     $this->assertThat($query, $containsSubQuery, $query);
     $this->assertThat($query, $containsFilter, $query);
     $this->assertThat($countQuery, $containsSubQuery, $countQuery);
     $this->assertThat($countQuery, $containsFilter, $countQuery);
 }