<commit_before><?php

namespace Neblion\ScrumBundle\Tests\Controller;

use Neblion\ScrumBundle\Tests\WebTestCase;

class ProjectReleaseControllerTest extends WebTestCase
{
    public function testIndex()
    {
        $client = $this->login('admin', 'test');
        $crawler = $client->request('GET', '/feature/1/list');
        // Test html template
        // Title of main widget-box
        $this->assertTrue($crawler->filter('html:contains("Features list")')->count() == 1);
        // 4 tr => 4 features for project->id = 1
        $this->assertEquals(4, $crawler->filter('table tbody tr')->count());
    }
    
    /*
    public function testNew()
    {
        // Test that simple member could not add a feature
        $client = $this->login('member', 'test');
        $crawler = $client->request('GET', '/feature/1/new');
        $this->assertEquals(403, $client->getResponse()->getStatusCode());
        
        // Test that developer member could not add a feature
        $client = $this->login('member', 'test');
        $crawler = $client->request('GET', '/feature/1/new');
        $this->assertEquals(403, $client->getResponse()->getStatusCode());
        
        // Test that scrumaster member could add a feature
        $client = $this->login('scrumaster', 'test');
        $crawler = $client->request('GET', '/feature/1/new');
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
        
        // Test that productowner member could add a feature
        $client = $this->login('productowner', 'test');
        $crawler = $client->request('GET', '/feature/1/new');
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
        
        // Test that admin member could add a feature
        $client = $this->login('admin', 'test');
        $crawler = $client->request('GET', '/feature/1/new');
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
        
        // Test form: empty fields
        $form = $crawler->selectButton('submit')->form();
        $crawler = $client->submit($form, array());
        
        // Test project name empty
        $this->assertTrue($crawler->filter('input#neblion_scrumbundle_featuretype_name ~ span.help-inline')->reduce(function ($node, $i) {
            if ($node->nodeValue != 'This value should not be blank.') {
                return false;
            }
        })->count() == 1);
        // Test project description empty
        $this->assertTrue($crawler->filter('textarea#neblion_scrumbundle_featuretype_description ~ span.help-inline')->reduce(function ($node, $i) {
            if ($node->nodeValue != 'This value should not be blank.') {
                return false;
            }
        })->count() == 1);
        // Test project sprint_duration empty
        $this->assertTrue($crawler->filter('input#neblion_scrumbundle_featuretype_color ~ span.help-inline')->reduce(function ($node, $i) {
            if ($node->nodeValue != 'This value should not be blank.') {
                return false;
            }
        })->count() == 1);
        
        
        // Test form: name field length > 50 and color not hexa code
        $form = $crawler->selectButton('submit')->form();
        $crawler = $client->submit($form, array(
            'neblion_scrumbundle_featuretype[name]'             => '012345678901234567890123456789012345678901234567890123456789',
            'neblion_scrumbundle_featuretype[description]'      => 'description',
            'neblion_scrumbundle_featuretype[color]'            => 'color',
        ));
        
        // name.length > 50
        $this->assertTrue($crawler->filter('input#neblion_scrumbundle_featuretype_name ~ span.help-inline')->reduce(function ($node, $i) {
            if ($node->nodeValue != 'This value is too long. It should have 50 character or less.|This value is too long. It should have 50 characters or less.') {
                return false;
            }
        })->count() == 1);
        // color not hexa code
        $this->assertTrue($crawler->filter('input#neblion_scrumbundle_featuretype_color ~ span.help-inline')->reduce(function ($node, $i) {
            if ($node->nodeValue != 'This is not a valid hexadecimal color!') {
                return false;
            }
        })->count() == 1);
    }
    
    public function testCreate()
    {
        // Test that productowner member could not add a feature
        $client = $this->login('productowner', 'test');
        $crawler = $client->request('GET', '/feature/1/new');
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
        
        // Test form
        $form = $crawler->selectButton('submit')->form();
        $crawler = $client->submit($form, array(
            'neblion_scrumbundle_featuretype[name]'             => 'feature-create-test',
            'neblion_scrumbundle_featuretype[description]'      => 'description',
            'neblion_scrumbundle_featuretype[color]'            => '#111111',
        ));
        
        $this->assertEquals(302, $client->getResponse()->getStatusCode());
        $crawler = $client->followRedirect();
        $this->assertTrue($crawler->filter('html:contains("Feature was created with success!")')->count() == 1);
    }
    
    public function testEdit()
    {
        // Test that simple member could not add a feature
        $client = $this->login('member', 'test');
        $crawler = $client->request('GET', '/feature/1/edit');
        $this->assertEquals(403, $client->getResponse()->getStatusCode());
        
        // Test that developer member could not add a feature
        $client = $this->login('member', 'test');
        $crawler = $client->request('GET', '/feature/1/edit');
        $this->assertEquals(403, $client->getResponse()->getStatusCode());
        
        // Test that scrumaster member could edit a feature
        $client = $this->login('scrumaster', 'test');
        $crawler = $client->request('GET', '/feature/1/edit');
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
        
        // Test that productowner member could edit a feature
        $client = $this->login('productowner', 'test');
        $crawler = $client->request('GET', '/feature/1/edit');
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
        
        // Test that productowner member could edit a feature
        $client = $this->login('admin', 'test');
        $crawler = $client->request('GET', '/feature/1/edit');
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
        
    }
    
    public function testUpdate()
    {
        $client = $this->login('admin', 'test');
        $crawler = $client->request('GET', '/feature/5/edit');
        
        // Test form
        $form = $crawler->selectButton('submit')->form();
        $crawler = $client->submit($form, array(
            'neblion_scrumbundle_featuretype[name]'             => 'feature-update-test',
            'neblion_scrumbundle_featuretype[description]'      => 'description-update',
            'neblion_scrumbundle_featuretype[color]'            => '#222222',
        ));
        
        $this->assertEquals(302, $client->getResponse()->getStatusCode());
        $crawler = $client->followRedirect();
        $this->assertTrue($crawler->filter('html:contains("Feature was updated with success!")')->count() == 1);
        
    }
    
    public function testDelete()
    {
        $client = $this->login('admin', 'test');
        
        // Test normal deletion
        $crawler = $client->request('GET', '/feature/5/delete');
        
        // Test form
        $form = $crawler->selectButton('submit')->form();
        $crawler = $client->submit($form, array());
        
        $this->assertEquals(302, $client->getResponse()->getStatusCode());
        $crawler = $client->followRedirect();
        // Test alert msg that confirm deletion
        $this->assertTrue($crawler->filter('html:contains("Feature was deleted with success!")')->count() == 1);
        // 4 tr => 4 features for project->id = 1
        $this->assertEquals(4, $crawler->filter('table tbody tr')->count());
        
        // Test feature deletion that could not be possible because of associated stories
        $crawler = $client->request('GET', '/feature/1/delete');
        $this->assertEquals(302, $client->getResponse()->getStatusCode());
        $crawler = $client->followRedirect();
        // Test alert msg that confirm deletion
        $this->assertTrue($crawler->filter('html:contains("You could not delete this Feature, stories associated with it!")')->count() == 1);
    }
    */
}<commit_msg>ProjectRelease add functional tests<commit_after><?php

namespace Neblion\ScrumBundle\Tests\Controller;

use Neblion\ScrumBundle\Tests\WebTestCase;

class ProjectReleaseControllerTest extends WebTestCase
{
    public function testIndex()
    {
        $client = $this->login('admin', 'test');
        $crawler = $client->request('GET', '/release/1');
        // Test html template
        // Title of main widget-box
        $this->assertTrue($crawler->filter('html:contains("Releases list")')->count() == 1);
        // 2 tr => 2 releases for project->id = 1
        $this->assertEquals(2, $crawler->filter('table tbody tr')->count());
    }
    
    
    public function testNew()
    {
        // Test that simple member could not add a feature
        $client = $this->login('member', 'test');
        $crawler = $client->request('GET', '/release/1/new');
        $this->assertEquals(403, $client->getResponse()->getStatusCode());
        
        // Test that developer member could not add a feature
        $client = $this->login('member', 'test');
        $crawler = $client->request('GET', '/release/1/new');
        $this->assertEquals(403, $client->getResponse()->getStatusCode());
        
        // Test that scrumaster member could add a feature
        $client = $this->login('scrumaster', 'test');
        $crawler = $client->request('GET', '/release/1/new');
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
        
        // Test that productowner member could add a feature
        $client = $this->login('productowner', 'test');
        $crawler = $client->request('GET', '/release/1/new');
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
        
        // Test that admin member could add a feature
        $client = $this->login('admin', 'test');
        $crawler = $client->request('GET', '/release/1/new');
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
        
        // Test form: empty fields
        $form = $crawler->selectButton('submit')->form();
        $crawler = $client->submit($form, array());
        
        // Test project name empty
        $this->assertTrue($crawler->filter('input#neblion_scrumbundle_projectreleasetype_name ~ span.help-inline')->reduce(function ($node, $i) {
            if ($node->nodeValue != 'This value should not be blank.') {
                return false;
            }
        })->count() == 1);
        // Test project description empty
        $this->assertTrue($crawler->filter('textarea#neblion_scrumbundle_projectreleasetype_description ~ span.help-inline')->reduce(function ($node, $i) {
            if ($node->nodeValue != 'This value should not be blank.') {
                return false;
            }
        })->count() == 1);
        // Test project sprint_duration empty
        $this->assertTrue($crawler->filter('input#neblion_scrumbundle_projectreleasetype_start ~ span.help-inline')->reduce(function ($node, $i) {
            if ($node->nodeValue != 'This value should not be blank.') {
                return false;
            }
        })->count() == 1);
        
        // Test form: name field length > 50 and color not hexa code
        $form = $crawler->selectButton('submit')->form();
        $crawler = $client->submit($form, array(
            'neblion_scrumbundle_projectreleasetype[name]'             => '012345678901234567890123456789012345678901234567890123456789',
            'neblion_scrumbundle_projectreleasetype[description]'      => 'description',
            'neblion_scrumbundle_projectreleasetype[start]'            => 'start',
            'neblion_scrumbundle_projectreleasetype[end]'              => 'end',
        ));
        // name.length > 50
        $this->assertTrue($crawler->filter('input#neblion_scrumbundle_projectreleasetype_name ~ span.help-inline')->reduce(function ($node, $i) {
            if ($node->nodeValue != 'This value is too long. It should have 50 character or less.|This value is too long. It should have 50 characters or less.') {
                return false;
            }
        })->count() == 1);
        // start is not a date value
        $this->assertTrue($crawler->filter('input#neblion_scrumbundle_projectreleasetype_start ~ span.help-inline')->reduce(function ($node, $i) {
            if ($node->nodeValue != 'This value is not valid.') {
                return false;
            }
        })->count() == 1);
        // end is not a date value
        $this->assertTrue($crawler->filter('input#neblion_scrumbundle_projectreleasetype_end ~ span.help-inline')->reduce(function ($node, $i) {
            if ($node->nodeValue != 'This value is not valid.') {
                return false;
            }
        })->count() == 1);
        
        // Test form with start date in an another release
        $form = $crawler->selectButton('submit')->form();
        $crawler = $client->submit($form, array(
            'neblion_scrumbundle_projectreleasetype[name]'             => 'release-test',
            'neblion_scrumbundle_projectreleasetype[description]'      => 'description',
            'neblion_scrumbundle_projectreleasetype[start]'            => '04/10/2012',
        ));
        $this->assertTrue($crawler->filter('html:contains("The release\'s dates overlap (Release-1)")')->count() == 1);
    }
    
    public function testCreate()
    {
        // Test that productowner member could not add a feature
        $client = $this->login('productowner', 'test');
        $crawler = $client->request('GET', '/release/1/new');
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
        
        // Test form
        // Test form with start date in an another release
        $form = $crawler->selectButton('submit')->form();
        $crawler = $client->submit($form, array(
            'neblion_scrumbundle_projectreleasetype[name]'             => 'release-test',
            'neblion_scrumbundle_projectreleasetype[description]'      => 'description',
            'neblion_scrumbundle_projectreleasetype[start]'            => '17/10/2012',
        ));
        $this->assertEquals(302, $client->getResponse()->getStatusCode());
        $crawler = $client->followRedirect();
        $this->assertTrue($crawler->filter('html:contains("Release was created with success!")')->count() == 1);
        $this->assertEquals(3, $crawler->filter('table tbody tr')->count());
    }
    
    public function testEdit()
    {
        // Test that simple member could not add a feature
        $client = $this->login('member', 'test');
        $crawler = $client->request('GET', '/release/1/edit');
        $this->assertEquals(403, $client->getResponse()->getStatusCode());
        
        // Test that developer member could not add a feature
        $client = $this->login('member', 'test');
        $crawler = $client->request('GET', '/release/1/edit');
        $this->assertEquals(403, $client->getResponse()->getStatusCode());
        
        // Test that scrumaster member could edit a feature
        $client = $this->login('scrumaster', 'test');
        $crawler = $client->request('GET', '/release/1/edit');
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
        
        // Test that productowner member could edit a feature
        $client = $this->login('productowner', 'test');
        $crawler = $client->request('GET', '/release/1/edit');
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
        
        // Test that productowner member could edit a feature
        $client = $this->login('admin', 'test');
        $crawler = $client->request('GET', '/release/1/edit');
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
    }

    public function testUpdate()
    {
        $client = $this->login('admin', 'test');
        $crawler = $client->request('GET', '/release/4/edit');
        
        // Test form
        $form = $crawler->selectButton('submit')->form();
        $crawler = $client->submit($form, array(
            'neblion_scrumbundle_projectreleasetype[name]'             => 'release-test-update',
            'neblion_scrumbundle_projectreleasetype[description]'      => 'description-update',
            'neblion_scrumbundle_projectreleasetype[start]'            => '17/10/2012',
        ));
        
        $this->assertEquals(302, $client->getResponse()->getStatusCode());
        $crawler = $client->followRedirect();
        $this->assertTrue($crawler->filter('html:contains("Release was updated with success!")')->count() == 1);
        
    }
    
    public function testDelete()
    {
        $client = $this->login('admin', 'test');
        
        // Test normal deletion
        $crawler = $client->request('GET', '/release/4/delete');
        
        // Test form
        $form = $crawler->selectButton('submit')->form();
        $crawler = $client->submit($form, array());
        
        $this->assertEquals(302, $client->getResponse()->getStatusCode());
        $crawler = $client->followRedirect();
        // Test alert msg that confirm deletion
        $this->assertTrue($crawler->filter('html:contains("Release was deleted with success!")')->count() == 1);
        // 4 tr => 4 features for project->id = 1
        $this->assertEquals(2, $crawler->filter('table tbody tr')->count());
        
        // Test release deletion that could not be possible because of associated stories
        $crawler = $client->request('GET', '/release/1/delete');
        $this->assertEquals(302, $client->getResponse()->getStatusCode());
        $crawler = $client->followRedirect();
        // Test alert msg that confirm deletion
        $this->assertTrue($crawler->filter('html:contains("Impossible to delete this release, there is at least a sprint attached to it!")')->count() == 1);
    }
}
{'fraction_non_alphanumeric': 0.16262658909717734, 'fraction_numerical': 0.01788407670760612, 'mean_word_length': 2.5207661672672104, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 329, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3230216', 'n_tokens_mistral': 5329, 'n_tokens_neox': 5099, 'n_words': 1095}