public function testGetsScheduleResourcesUserHasAdminRightsTo() { $scheduleId = 100; $user = $this->getMock('User'); $this->userRepository->expects($this->once())->method('LoadById')->with($this->equalTo($this->fakeUser->UserId))->will($this->returnValue($user)); $ra = new FakeResourceAccess(); $this->db->SetRows($ra->GetRows()); $user->expects($this->at(0))->method('IsResourceAdminFor')->with($this->equalTo($ra->_Resources[0]))->will($this->returnValue(false)); $user->expects($this->at(1))->method('IsResourceAdminFor')->with($this->equalTo($ra->_Resources[1]))->will($this->returnValue(true)); $repo = new ResourceAdminResourceRepository($this->userRepository, $this->fakeUser); $resources = $repo->GetScheduleResources($scheduleId); $this->assertTrue($this->db->ContainsCommand(new GetScheduleResourcesCommand($scheduleId))); $this->assertEquals(1, count($resources)); $this->assertEquals(2, $resources[0]->GetId()); }
public function testLoadsResourceById() { $id = 1; $fr = new FakeResourceAccess(); $rows = $fr->GetRows(); $this->db->SetRow(0, $rows); $car = new CustomAttributeValueRow(); $car->With(1, 'value')->With(2, 'value2'); $this->db->SetRow(1, $car->Rows()); $loadResourceCommand = new GetResourceByIdCommand($id); $attributes = new GetAttributeValuesCommand(1, CustomAttributeCategory::RESOURCE); $resource = $this->repository->LoadById($id); $this->assertTrue($this->db->ContainsCommand($loadResourceCommand)); $this->assertTrue($this->db->ContainsCommand($attributes)); $this->assertNotNull($resource); $this->assertEquals('value', $resource->GetAttributeValue(1)); $this->assertEquals('value2', $resource->GetAttributeValue(2)); }