<commit_before><?php

namespace NS\SentinelBundle\Tests;

use \Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use \Symfony\Component\BrowserKit\Cookie;
use \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;

class ApplicationAvailabilityTest extends WebTestCase
{
    /**
     * @dataProvider urlProvider
     * @param $url
     */
    public function testPageIsSuccessful($url)
    {
        $client = $this->getClient();
        $client->followRedirects();
        $client->request('GET', $url);

        if(!$client->getResponse()->isSuccessful()) {
          file_put_contents(sprintf('/tmp/%s.log',str_replace('/','-',$url)),$client->getResponse()->getContent());
        }

        $this->assertTrue($client->getResponse()->isSuccessful());
    }

    public function urlProvider()
    {
        return array(
            array('/en/ibd'),
            array('/en/rota'),
            array('/en/ibd/reports/data-quality'),
            array('/en/ibd/reports/site-performance'),
            array('/en/ibd/reports/data-linking'),
            array('/en/ibd/reports/annual-age-distribution'),
            array('/en/ibd/reports/percent-enrolled'),
            array('/en/ibd/reports/field-population'),
            array('/en/ibd/reports/culture-positive'),
            array('/en/rota/reports/data-quality'),
            array('/en/rota/reports/site-performance'),
            array('/en/rota/reports/data-linking'),
            array('/en/profile'),
        );
    }

    private function getClient()
    {
        $client    = self::createClient();
        $container = $client->getContainer();
        $user      =  $container->get('doctrine.orm.entity_manager')
            ->createQuery("SELECT u,a,l FROM NS\SentinelBundle\Entity\User u LEFT JOIN u.acls a LEFT JOIN u.referenceLab l WHERE u.email = :email")
            ->setParameter('email', '<EMAIL>')
            ->getSingleResult();

        $session  = $container->get('session');
        $firewall = 'main_app';

        $this->assertNotEmpty($user->getRoles());
        $token = new UsernamePasswordToken($user, $user->getPassword(), $firewall, $user->getRoles());

        $session->set('_security_' . $firewall, serialize($token));
        $session->save();

        $cookie = new Cookie($session->getName(), $session->getId());
        $client->getCookieJar()->set($cookie);
        $client->followRedirects();

        return $client;
    }
}<commit_msg>Added tests to the filter form pages<commit_after><?php

namespace NS\SentinelBundle\Tests;

use \Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use \Symfony\Component\BrowserKit\Cookie;
use \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;

class ApplicationAvailabilityTest extends WebTestCase
{
    /**
     * @dataProvider urlProvider
     * @param $url
     */
    public function testPageIsSuccessful($url)
    {
        $client = $this->getClient();
        $client->followRedirects();
        $client->request('GET', $url);

        if(!$client->getResponse()->isSuccessful()) {
          file_put_contents(sprintf('/tmp/%s.log',str_replace('/','-',$url)),$client->getResponse()->getContent());
        }

        $this->assertTrue($client->getResponse()->isSuccessful());
    }

    public function urlProvider()
    {
        return array(
            array('/en/ibd'),
            array('/en/rota'),
            array('/en/ibd/reports/data-quality'),
            array('/en/ibd/reports/site-performance'),
            array('/en/ibd/reports/data-linking'),
            array('/en/ibd/reports/annual-age-distribution'),
            array('/en/ibd/reports/percent-enrolled'),
            array('/en/ibd/reports/field-population'),
            array('/en/ibd/reports/culture-positive'),
            array('/en/rota/reports/data-quality'),
            array('/en/rota/reports/site-performance'),
            array('/en/rota/reports/data-linking'),
            array('/en/profile'),
        );
    }

    /**
     * @param $url
     * @param string $button
     * @param array $params
     *
     * @dataProvider getFormUrls
     * @group form
     */
    public function testFormSubmission($url, $button, array $params)
    {
        $client = $this->getClient();
        $client->followRedirects();
        $crawler = $client->request('GET', $url);

        $form = $crawler->selectButton($button)->form();
        foreach($params as $key=>$value) {
            $form[$key] = $value;
        }

        $client->submit($form);

        if(!$client->getResponse()->isSuccessful()) {
            file_put_contents(sprintf('/tmp/%s-form.log',str_replace('/','-',$url)),$client->getResponse()->getContent());
        }
    }

    public function getFormUrls()
    {
        return array(
//            array('/en/ibd','ibd_filter_form[find]',array('ibd_filter_form[id]'=>'123')),
//            array('/en/rota'),
            array('/en/ibd/reports/data-quality','IBDReportFilterType[filter]', array('IBDReportFilterType[adm_date][left_date]'=>'01/01/2014','IBDReportFilterType[adm_date][right_date]'=>'12/31/2014')),
            array('/en/ibd/reports/site-performance','QuarterlyReportFilter[filter]', array('QuarterlyReportFilter[year]'=>2014)),
            array('/en/ibd/reports/data-linking','IBDQuarterlyLinkingReportFilter[filter]', array('IBDQuarterlyLinkingReportFilter[year]'=>2014)),
            array('/en/ibd/reports/annual-age-distribution','IBDReportFilterType[filter]', array('IBDReportFilterType[adm_date][left_date]'=>'01/01/2014','IBDReportFilterType[adm_date][right_date]'=>'12/31/2014')),
            array('/en/ibd/reports/percent-enrolled','IBDReportFilterType[filter]', array('IBDReportFilterType[adm_date][left_date]'=>'01/01/2014','IBDReportFilterType[adm_date][right_date]'=>'12/31/2014')),
            array('/en/ibd/reports/field-population','IBDReportFilterType[filter]', array('IBDReportFilterType[adm_date][left_date]'=>'01/01/2014','IBDReportFilterType[adm_date][right_date]'=>'12/31/2014')),
            array('/en/ibd/reports/culture-positive','IBDReportFilterType[filter]', array('IBDReportFilterType[adm_date][left_date]'=>'01/01/2014','IBDReportFilterType[adm_date][right_date]'=>'12/31/2014')),
            array('/en/rota/reports/data-quality','RotaVirusReportFilterType[filter]', array('RotaVirusReportFilterType[adm_date][left_date]'=>'01/01/2014','RotaVirusReportFilterType[adm_date][right_date]'=>'12/31/2014')),
            array('/en/rota/reports/site-performance','QuarterlyReportFilter[filter]', array('QuarterlyReportFilter[year]'=>2014)),
            array('/en/rota/reports/data-linking','RotaVirusQuarterlyLinkingReportFilter[filter]', array('RotaVirusQuarterlyLinkingReportFilter[year]'=>2014)),
//            array('/en/profile','submit',array('ns_sentinelbundle_user[name]'=>'Test User Name')),
        );
    }

    private function getClient()
    {
        $client    = self::createClient();
        $container = $client->getContainer();
        $user      =  $container->get('doctrine.orm.entity_manager')
            ->createQuery("SELECT u,a,l FROM NS\SentinelBundle\Entity\User u LEFT JOIN u.acls a LEFT JOIN u.referenceLab l WHERE u.email = :email")
            ->setParameter('email', '<EMAIL>')
            ->getSingleResult();

        $session  = $container->get('session');
        $firewall = 'main_app';

        $this->assertNotEmpty($user->getRoles());
        $token = new UsernamePasswordToken($user, $user->getPassword(), $firewall, $user->getRoles());

        $session->set('_security_' . $firewall, serialize($token));
        $session->save();

        $cookie = new Cookie($session->getName(), $session->getId());
        $client->getCookieJar()->set($cookie);
        $client->followRedirects();

        return $client;
    }
}
{'fraction_non_alphanumeric': 0.1797075423293997, 'fraction_numerical': 0.014751154438173422, 'mean_word_length': 3.0929133858267717, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 88, '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': '4738208', 'n_tokens_mistral': 2471, 'n_tokens_neox': 2325, 'n_words': 264}