<commit_before><?php
namespace Notejam\NoteBundle\Tests\Controller;

use Liip\FunctionalTestBundle\Test\WebTestCase;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Notejam\UserBundle\Entity\User;

class PadControllerTest extends WebTestCase
{
    public function setUp() 
    {
        $this->loadFixtures(array());
        // init kernel to init entity manager
        static::$kernel = static::createKernel(array('environment' => 'test'));
        static::$kernel->boot();
        $this->em = static::$kernel->getContainer()
            ->get('doctrine')
            ->getManager() ;
    }
    
    private function _createUser($email, $password) {
        $user = new User();

        $encoder = static::$kernel->getContainer()
            ->get('security.encoder_factory')
            ->getEncoder($user);

        $password = $encoder->encodePassword($password, $user->getSalt());
        $user->setEmail($email)
             ->setPassword($password);

        $this->em->persist($user);
        $this->em->flush();

        return $user;
    }

    private function _signIn($user)
    {
        $client = static::createClient();
        $session = $client->getContainer()->get('session');

        $firewall = 'main';
        $token = new UsernamePasswordToken(
            $user, $user->getPassword(), $firewall, array('ROLE_USER')
        );
        $session->set('_security_'.$firewall, serialize($token));
        $session->save();

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

    public function testCreatePadSuccess()
    {
        $email = '<EMAIL>';
        $password = '<PASSWORD>';
        $user = $this->_createUser($email, $password);

        $client = $this->_signIn($user);
        $crawler = $client->request('GET', '/pads/create');
        $form = $crawler->filter('button')->form();
        $crawler = $client->submit($form);
        $this->assertEquals(1, $crawler->filter('ul.errorlist > li')->count());
    }

    public function testCreatePadErrorRequiredFields() 
    {
    }
<commit_msg>Symfony: Implemented testCreatePadSuccess<commit_after><?php
namespace Notejam\NoteBundle\Tests\Controller;

use Liip\FunctionalTestBundle\Test\WebTestCase;
use Symfony\Component\BrowserKit\Cookie;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Notejam\UserBundle\Entity\User;

class PadControllerTest extends WebTestCase
{
    public function setUp() 
    {
        $this->loadFixtures(array());
        // init kernel to init entity manager
        static::$kernel = static::createKernel(array('environment' => 'test'));
        static::$kernel->boot();
        $this->em = static::$kernel->getContainer()
            ->get('doctrine')
            ->getManager() ;
    }
    
    private function _createUser($email, $password) {
        $user = new User();

        $encoder = static::$kernel->getContainer()
            ->get('security.encoder_factory')
            ->getEncoder($user);

        $password = $encoder->encodePassword($password, $user->getSalt());
        $user->setEmail($email)
             ->setPassword($password);

        $this->em->persist($user);
        $this->em->flush();

        return $user;
    }

    private function _signIn($user)
    {
        $client = static::createClient();
        $session = $client->getContainer()->get('session');

        $firewall = 'main';
        $token = new UsernamePasswordToken(
            $user, $user->getPassword(), $firewall, array('ROLE_USER')
        );
        $session->set('_security_'.$firewall, serialize($token));
        $session->save();

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

    public function testCreatePadSuccess()
    {
        $email = '<EMAIL>';
        $password = '<PASSWORD>';
        $user = $this->_createUser($email, $password);

        $client = $this->_signIn($user);
        $client->followRedirects();
        $crawler = $client->request('GET', '/pads/create');
        $form = $crawler->filter('button')->form();
        $form['pad[name]'] = 'Pad';
        $crawler = $client->submit($form);
        $this->assertEquals(1, $crawler->filter('nav > ul > li')->count());
        $this->assertCount(
            1, $this->em->getRepository('NotejamNoteBundle:Pad')->findAll()
        );
    }

    public function testCreatePadErrorRequiredFields() 
    {
        $email = '<EMAIL>';
        $password = '<PASSWORD>';
        $user = $this->_createUser($email, $password);

        $client = $this->_signIn($user);
        $crawler = $client->request('GET', '/pads/create');
        $form = $crawler->filter('button')->form();
        $crawler = $client->submit($form);
        $this->assertEquals(1, $crawler->filter('ul.errorlist > li')->count());
    }

{'fraction_non_alphanumeric': 0.1736957825304817, 'fraction_numerical': 0.0007995202878273036, 'mean_word_length': 2.748314606741573, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 99, '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': '6819163', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1411, 'n_words': 236}