public function indexAction() { if (!$this->zfcUserAuthentication()->hasIdentity()) { return $this->redirect()->toRoute(static::ROUTE_LOGIN); } $viewModel = new ViewModel(['repositories' => $this->moduleService->currentUserModules()]); $viewModel->setTemplate('zfc-user/user/index'); return $viewModel; }
/** * Register a new Module * * @return Http\Response * @throws Exception\InvalidDataException * @throws Exception\RepositoryException */ public function addAction() { if (!$this->zfcUserAuthentication()->hasIdentity()) { return $this->redirect()->toRoute('zfcuser/login'); } $request = $this->getRequest(); if (!$request->isPost()) { throw Exception\InvalidDataException::fromInvalidRequest('Something went wrong with the post values of the request...', $this->getRequest()); } $postParams = $request->getPost(); $repo = $postParams->get('repo'); $owner = $postParams->get('owner'); $repository = $this->repositoryRetriever->getUserRepositoryMetadata($owner, $repo); if (!$repository instanceof \stdClass) { throw Exception\RepositoryException::fromNotFoundRepository('Not able to fetch the repository from GitHub due to an unknown error.', $owner, $repo); } if ($repository->fork || !$repository->permissions->push) { throw Exception\RepositoryException::fromInsufficientPermissions('You have no permission to add this module. The reason might be that you are neither the owner nor a collaborator of this repository.', $repository->full_name, ['pushAccess', 'noFork']); } if (!$this->moduleService->isModule($repository)) { throw Exception\RepositoryException::fromNonModuleRepository($repository->name . ' is not a Zend Framework Module', $repository->full_name); } $module = $this->moduleService->register($repository); $this->flashMessenger()->addSuccessMessage($module->getName() . ' has been added to ZF Modules'); return $this->redirect()->toRoute('zfcuser'); }
public function testRegisterUpdatesExistingModule() { $repository = $this->repository(); $module = $this->getMockBuilder(Entity\Module::class)->getMock(); $module->expects($this->once())->method('setName')->with($this->equalTo($repository->name)); $module->expects($this->once())->method('setDescription')->with($this->equalTo($repository->description)); $module->expects($this->once())->method('setUrl')->with($this->equalTo($repository->html_url)); $module->expects($this->once())->method('setOwner')->with($this->equalTo($repository->owner->login)); $module->expects($this->once())->method('setPhotoUrl')->with($this->equalTo($repository->owner->avatar_url)); $moduleMapper = $this->getMockBuilder(Mapper\Module::class)->getMock(); $moduleMapper->expects($this->once())->method('findByUrl')->with($this->equalTo($repository->html_url))->willReturn($module); $moduleMapper->expects($this->once())->method('update')->with($this->equalTo($module)); $githubClient = $this->getMockBuilder(Client::class)->disableOriginalConstructor()->getMock(); $service = new Service\Module($moduleMapper, $githubClient); $this->assertSame($module, $service->register($repository)); }