diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index 1906fb8c..7683e49e 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -119,7 +119,7 @@ class ProjectController extends \PHPCI\Controller } $project = $this->projectStore->getById($projectId); - $this->projectStore->delete($project); + $this->projectService->delete($project); header('Location: '.PHPCI_URL); exit; @@ -197,7 +197,7 @@ class ProjectController extends \PHPCI\Controller 'allow_public_status' => $this->getParam('allow_public_status', 0), ); - $project = $this->projectService->createProject($title, $reference, $type, $options); + $project = $this->projectService->createProject($title, $type, $reference, $options); header('Location: '.PHPCI_URL.'project/view/' . $project->getId()); die; } @@ -247,21 +247,18 @@ class ProjectController extends \PHPCI\Controller return $view->render(); } - $values = $form->getValues(); - $values['ssh_private_key'] = $values['key']; - $values['ssh_public_key'] = $values['pubkey']; + $title = $this->getParam('title', 'New Project'); + $reference = $this->getParam('reference', null); + $type = $this->getParam('type', null); - if ($values['type'] == "gitlab") { - preg_match('`^(.*)@(.*):(.*)/(.*)\.git`', $values['reference'], $matches); - $info = array(); - $info["user"] = $matches[1]; - $info["domain"] = $matches[2]; - $values['access_information'] = serialize($info); - $values['reference'] = $matches[3] . "/" . $matches[4]; - } + $options = array( + 'ssh_private_key' => $this->getParam('key', null), + 'ssh_public_key' => $this->getParam('pubkey', null), + 'build_config' => $this->getParam('build_config', null), + 'allow_public_status' => $this->getParam('allow_public_status', 0), + ); - $project->setValues($values); - $project = $this->projectStore->save($project); + $project = $this->projectService->updateProject($project, $title, $type, $reference, $options); header('Location: '.PHPCI_URL.'project/view/' . $project->getId()); die; @@ -332,7 +329,7 @@ class ProjectController extends \PHPCI\Controller $field = Form\Element\Checkbox::create('allow_public_status', $label, false); $field->setContainerClass('form-group'); $field->setCheckedValue(1); - $field->setValue(1); + $field->setValue(0); $form->addField($field); $field = new Form\Element\Submit(); diff --git a/PHPCI/Service/ProjectService.php b/PHPCI/Service/ProjectService.php index ee2ef7b2..26954ddc 100644 --- a/PHPCI/Service/ProjectService.php +++ b/PHPCI/Service/ProjectService.php @@ -57,6 +57,7 @@ class ProjectService $project->setTitle($title); $project->setType($type); $project->setReference($reference); + $project->setAllowPublicStatus(0); // Handle extra project options: if (array_key_exists('ssh_private_key', $options)) { @@ -82,6 +83,16 @@ class ProjectService return $this->projectStore->save($project); } + /** + * Delete a given project. + * @param Project $project + * @return bool + */ + public function deleteProject(Project $project) + { + return $this->projectStore->delete($project); + } + /** * In circumstances where it is necessary, populate access information based on other project properties. * @see ProjectService::createProject() diff --git a/Tests/PHPCI/Service/MockProjectStore.php b/Tests/PHPCI/Service/MockProjectStore.php deleted file mode 100644 index a19f5e69..00000000 --- a/Tests/PHPCI/Service/MockProjectStore.php +++ /dev/null @@ -1,15 +0,0 @@ -setId(1); - return $project; - } -} diff --git a/Tests/PHPCI/Service/ProjectServiceTest.php b/Tests/PHPCI/Service/ProjectServiceTest.php index b0ff30d6..146eb97c 100644 --- a/Tests/PHPCI/Service/ProjectServiceTest.php +++ b/Tests/PHPCI/Service/ProjectServiceTest.php @@ -11,7 +11,6 @@ namespace PHPCI\Service\Tests; use PHPCI\Model\Project; use PHPCI\Service\ProjectService; -use Tests\PHPCI\Service\MockProjectStore; /** * Unit tests for the ProjectService class. @@ -32,7 +31,11 @@ class ProjectServiceTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->mockProjectStore = new MockProjectStore(); + $this->mockProjectStore = $this->getMock('PHPCI\Store\ProjectStore'); + $this->mockProjectStore->expects($this->any()) + ->method('save') + ->will($this->returnArgument(0)); + $this->testedService = new ProjectService($this->mockProjectStore); } @@ -98,4 +101,39 @@ class ProjectServiceTest extends \PHPUnit_Framework_TestCase $this->assertEquals('After Reference', $returnValue->getReference()); $this->assertEquals('bitbucket', $returnValue->getType()); } + + /** + * @covers PHPUnit::execute + */ + public function testExecute_EmptyPublicStatus() + { + $project = new Project(); + $project->setAllowPublicStatus(1); + + $options = array( + 'ssh_private_key' => 'private', + 'ssh_public_key' => 'public', + 'build_config' => 'config', + ); + + $returnValue = $this->testedService->updateProject($project, 'Test Project', 'github', 'block8/phpci', $options); + + $this->assertEquals(0, $returnValue->getAllowPublicStatus()); + } + + /** + * @covers PHPUnit::execute + */ + public function testExecute_DeleteProject() + { + $store = $this->getMock('PHPCI\Store\ProjectStore'); + $store->expects($this->once()) + ->method('delete') + ->will($this->returnValue(true)); + + $service = new ProjectService($store); + $project = new Project(); + + $this->assertEquals(true, $service->deleteProject($project)); + } }