|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace VersionControl\GitControlBundle\Tests\Controller; |
| 4 | + |
| 5 | + |
| 6 | +class ProjectEnvironmentControllerTest extends BaseControllerTestCase |
| 7 | +{ |
| 8 | + |
| 9 | + public function testNewGitProjectEnvironmentScenario() |
| 10 | + { |
| 11 | + $user = $this->createAuthorizedClient(); |
| 12 | + // Create a new client to browse the application |
| 13 | + |
| 14 | + $project = $this->getProject($user); |
| 15 | + |
| 16 | + |
| 17 | + // List users for project |
| 18 | + $url = $this->client->getContainer()->get('router')->generate('projectenvironment_new', array('id'=>$project->getId())); |
| 19 | + $crawler = $this->client->request('GET', $url,array(), array(), array( |
| 20 | + 'HTTP_X-Requested-With' => 'XMLHttpRequest', |
| 21 | + )); |
| 22 | + $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET ".$url); |
| 23 | + |
| 24 | + $gitPath = $this->createTempFolder('NewRepo'); |
| 25 | + // Fill in the form and submit it |
| 26 | + $form = $crawler->selectButton('Create')->form(array( |
| 27 | + 'versioncontrol_gitcontrolbundle_projectenvironment[title]' => 'Test New Project Environment', |
| 28 | + 'versioncontrol_gitcontrolbundle_projectenvironment[description]' => 'Test project environment with new git folder creation', |
| 29 | + 'versioncontrol_gitcontrolbundle_projectenvironment[path]' => $gitPath, |
| 30 | + )); |
| 31 | + |
| 32 | + $this->client->submit($form); |
| 33 | + $crawler = $this->client->followRedirect(); |
| 34 | + |
| 35 | + $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), "Unexpected HTTP status code for creating new project environment"); |
| 36 | + $this->assertGreaterThan(0, $crawler->filter('a:contains("Test New Project Environment")')->count(), 'Missing element a:contains(""Test New Project Environment")'); |
| 37 | + |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Test exisitng Git project. Test does not create a git repo so we test that |
| 42 | + * project path does not contain a git repo ;-( |
| 43 | + * @todo Does not validate in crawler. no idea why. needs more debugging |
| 44 | + */ |
| 45 | + public function testExistingGitProjectEnvironmentScenario() |
| 46 | + { |
| 47 | + $user = $this->createAuthorizedClient(); |
| 48 | + // Create a new client to browse the application |
| 49 | + |
| 50 | + $project = $this->getProject($user); |
| 51 | + |
| 52 | + |
| 53 | + // List users for project |
| 54 | + $url = $this->client->getContainer()->get('router')->generate('projectenvironment_existing', array('id'=>$project->getId())); |
| 55 | + $crawler = $this->client->request('GET', $url,array(), array(), array( |
| 56 | + 'HTTP_X-Requested-With' => 'XMLHttpRequest', |
| 57 | + )); |
| 58 | + $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /userprojects/"); |
| 59 | + |
| 60 | + $gitPath = $this->createTempFolder('NewExistingRepo'); |
| 61 | + |
| 62 | + // Fill in the form and submit it |
| 63 | + $form = $crawler->selectButton('Create')->form(array( |
| 64 | + 'versioncontrol_gitcontrolbundle_projectenvironment[title]' => 'Test New Project Environment with Existing git Repo', |
| 65 | + 'versioncontrol_gitcontrolbundle_projectenvironment[description]' => 'Test project environment with existing git folder creation', |
| 66 | + 'versioncontrol_gitcontrolbundle_projectenvironment[path]' => $gitPath, |
| 67 | + )); |
| 68 | + |
| 69 | + $this->client->submit($form); |
| 70 | + $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), "Unexpected HTTP status code for creating new existing git repo project environment"); |
| 71 | + |
| 72 | + //$html = $crawler->html(); |
| 73 | + //$showUrl = $this->client->getRequest()->getUri(); |
| 74 | + //$this->assertGreaterThan(0, $crawler->filter('.alert-danger')->count(), 'Missing validation errors when there should be some. Element .alert-danger is missing.'.$showUrl); |
| 75 | + |
| 76 | + } |
| 77 | + |
| 78 | + public function testCloneGitProjectEnvironmentScenario() |
| 79 | + { |
| 80 | + $user = $this->createAuthorizedClient(); |
| 81 | + // Create a new client to browse the application |
| 82 | + |
| 83 | + $project = $this->getProject($user); |
| 84 | + |
| 85 | + |
| 86 | + // List users for project |
| 87 | + $url = $this->client->getContainer()->get('router')->generate('projectenvironment_clone', array('id'=>$project->getId())); |
| 88 | + $crawler = $this->client->request('GET', $url,array(), array(), array( |
| 89 | + 'HTTP_X-Requested-With' => 'XMLHttpRequest', |
| 90 | + )); |
| 91 | + $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /userprojects/"); |
| 92 | + |
| 93 | + $gitPath = $this->createTempFolder('NewCloneRepo'); |
| 94 | + // Fill in the form and submit it |
| 95 | + $form = $crawler->selectButton('Create')->form(array( |
| 96 | + 'versioncontrol_gitcontrolbundle_projectenvironment[title]' => 'Test Clone Project Environment', |
| 97 | + 'versioncontrol_gitcontrolbundle_projectenvironment[description]' => 'Test Clone project environment with new git folder creation', |
| 98 | + 'versioncontrol_gitcontrolbundle_projectenvironment[path]' => $gitPath, |
| 99 | + 'versioncontrol_gitcontrolbundle_projectenvironment[gitCloneLocation]' => 'https://github.com/SSHVersionControl/test.git', |
| 100 | + )); |
| 101 | + |
| 102 | + $this->client->submit($form); |
| 103 | + $crawler = $this->client->followRedirect(); |
| 104 | + |
| 105 | + $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), "Unexpected HTTP status code for creating new project environment"); |
| 106 | + $this->assertGreaterThan(0, $crawler->filter('a:contains("Test Clone Project Environment")')->count(), 'Missing element a:contains("Test Clone Project Environment")'); |
| 107 | + |
| 108 | + |
| 109 | + } |
| 110 | + |
| 111 | +} |
0 commit comments