<commit_before><?php
use Jarnstedt\Former\Former;
use \Mockery as m;
use Illuminate\Http\Request;
use Illuminate\Html\HtmlBuilder;
use Illuminate\Routing\UrlGenerator;
use Illuminate\Routing\RouteCollection;
use Illuminate\Html\FormBuilder;

class FormerTest extends \PHPUnit_Framework_TestCase {

    public function setUp()
    {
        parent::setUp();
        $this->urlGenerator = new UrlGenerator(new RouteCollection, Request::create('/foo', 'GET'));
        $this->htmlBuilder = new HtmlBuilder($this->urlGenerator);
        $this->config = m::mock('\Illuminate\Config\Repository');
        $this->session = m::mock('\Illuminate\Session\Store');
        $this->config->shouldReceive('get')
            ->andReturn('');

        $this->session->shouldReceive('get')
            ->once()
            ->andReturn(array());
        $this->session->shouldReceive('getToken')
            ->once()
            ->andReturn('');
        
        $this->former = new Former(
            $this->htmlBuilder,
            $this->urlGenerator,
            $this->session,
            $this->config
        );
    }

    public function tearDown()
    {
        m::close();
    }

    /**
     * Test creating Former object
     */
    public function testCreate()
    {
        $this->assertInstanceOf('Jarnstedt\Former\Former', $this->former);
    }

    public function testMakeWithNoParameters()
    {
        $result = $this->former->make();
        $this->assertInstanceOf('Jarnstedt\Former\Former', $result);
    }

    public function testOpen()
    {
        $result = $this->former->make(array('foo' => 'bar'));
        $this->assertInstanceOf('Jarnstedt\Former\Former', $result);
        $this->session->shouldReceive('getOldInput')->andReturn('test');
        $html = $result->open();

        $this->assertStringEndsWith('value="test">', $html);
    }

    /**
     * Test text input field
     */
    public function testText()
    {
        // mock old input
        $this->session->shouldReceive('getOldInput')
            ->andReturn(null);

        $form = $this->former->make();
        $text = $form->text('name', 'Text.req', 'default value', array('class' => 'custom-class'));

        $this->assertContains('for="name"', $text);
        $this->assertContains('Text', $text);
        $this->assertContains('default value', $text);
        $this->assertContains('custom-class', $text);

        $text2 = $form->text('foobar', null, null, array('attribute' => 'something'));
        $this->assertContains('name="foobar"', $text2);
        $this->assertContains('attribute="something"', $text2);
    }

    /**
     * Test select input field
     */
    public function testSelect()
    {
        // mock old input
        $this->session->shouldReceive('getOldInput')
            ->andReturn(null);

        $form = $this->former->make();
        $options = array(
            'Example',
            'First',
            'Second',
        );
        $html = $form->select('foobar', 'Label', $options);
        $this->assertContains('name="foobar"', $html);
        $this->assertContains('Label', $html);
    }

}<commit_msg>Add test for submit button.<commit_after><?php
use Jarnstedt\Former\Former;
use \Mockery as m;
use Illuminate\Http\Request;
use Illuminate\Html\HtmlBuilder;
use Illuminate\Routing\UrlGenerator;
use Illuminate\Routing\RouteCollection;
use Illuminate\Html\FormBuilder;

class FormerTest extends \PHPUnit_Framework_TestCase {

    public function setUp()
    {
        parent::setUp();
        $this->urlGenerator = new UrlGenerator(new RouteCollection, Request::create('/foo', 'GET'));
        $this->htmlBuilder = new HtmlBuilder($this->urlGenerator);
        $this->config = m::mock('\Illuminate\Config\Repository');
        $this->session = m::mock('\Illuminate\Session\Store');
        $this->config->shouldReceive('get')
            ->andReturn('');

        $this->session->shouldReceive('get')
            ->once()
            ->andReturn(array());
        $this->session->shouldReceive('getToken')
            ->once()
            ->andReturn('');
        
        $this->former = new Former(
            $this->htmlBuilder,
            $this->urlGenerator,
            $this->session,
            $this->config
        );
    }

    public function tearDown()
    {
        m::close();
    }

    /**
     * Test creating Former object
     */
    public function testCreate()
    {
        $this->assertInstanceOf('Jarnstedt\Former\Former', $this->former);
    }

    public function testMakeWithNoParameters()
    {
        $result = $this->former->make();
        $this->assertInstanceOf('Jarnstedt\Former\Former', $result);
    }

    public function testOpen()
    {
        $result = $this->former->make(array('foo' => 'bar'));
        $this->assertInstanceOf('Jarnstedt\Former\Former', $result);
        $this->session->shouldReceive('getOldInput')->andReturn('test');
        $html = $result->open();

        $this->assertStringEndsWith('value="test">', $html);
    }

    /**
     * Test text input field
     */
    public function testText()
    {
        // mock old input
        $this->session->shouldReceive('getOldInput')
            ->andReturn(null);

        $form = $this->former->make();
        $text = $form->text('name', 'Text.req', 'default value', array('class' => 'custom-class'));

        $this->assertContains('for="name"', $text);
        $this->assertContains('Text', $text);
        $this->assertContains('default value', $text);
        $this->assertContains('custom-class', $text);

        $text2 = $form->text('foobar', null, null, array('attribute' => 'something'));
        $this->assertContains('name="foobar"', $text2);
        $this->assertContains('attribute="something"', $text2);
    }

    /**
     * Test select input field
     */
    public function testSelect()
    {
        // mock old input
        $this->session->shouldReceive('getOldInput')
            ->andReturn(null);

        $form = $this->former->make();
        $options = array(
            'Example',
            'First',
            'Second',
        );
        $html = $form->select('foobar', 'Label', $options);
        $this->assertContains('name="foobar"', $html);
        $this->assertContains('Label', $html);
    }

    /**
     * Test submit button
     */
    public function testSubmit()
    {
        // mock old input
        $this->session->shouldReceive('getOldInput')
            ->andReturn(null);

        $form = $this->former->make();
        $btn1 = $form->submit("Submit");
        $this->assertEquals('<button type="submit" class="btn">Submit</button>', $btn1);
        $btn2 = $form->submit("Submit", array('class' => 'foobar'));
        $this->assertContains('foobar', $btn2);
    }

}
{'fraction_non_alphanumeric': 0.1750627862313488, 'fraction_numerical': 0.0014773230905599055, 'mean_word_length': 2.4174659262998484, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 133, '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': '471884', 'n_tokens_mistral': 1959, 'n_tokens_neox': 1931, 'n_words': 335}