<commit_before><?php

use UWDOEM\Framework\Field\Field;
use UWDOEM\Framework\Writer\Writer;
use UWDOEM\Framework\Form\FormAction\FormAction;
use UWDOEM\Framework\FieldBearer\FieldBearerBuilder;
use UWDOEM\Framework\Form\FormBuilder;
use UWDOEM\Framework\Section\SectionBuilder;
use UWDOEM\Framework\Page\PageBuilder;
use UWDOEM\Framework\Page\Page;


class WriterTest extends PHPUnit_Framework_TestCase
{
    public function testVisitField() {
        $writer = new Writer();

        /* A literal field */
        $field = new Field("literal", "A literal field", "initial", true, [], 200);
        $this->assertContains("initial", $writer->visitField($field));

        /* A section-label field */
        $field = new Field("section-label", "A section-label field", "initial");
        $this->assertContains("A section-label field", $writer->visitField($field));
        $this->assertNotContains("initial", $writer->visitField($field));

        /* A choice field */
        $field = new Field("choice", "A literal field", "initial", true, ["first choice", "second choice"], 200);

        $result = $writer->visitField($field);
        $this->assertContains("first choice", $result);
        $this->assertContains("second choice", $result);

        /* A multiple choice field */
        $field = new Field("multiple-choice", "A multiple-choice field", "initial", true, ["first choice", "second choice"], 200);

        $result = $writer->visitField($field);
        $this->assertContains("first choice", $result);
        $this->assertContains("second choice", $result);

        /* A text field */
        $field = new Field("text", "A text field", "5", true, [], 200);

        // Get result and strip quotes, for easier analysis
        $result = str_replace(['"', "'"], "", $writer->visitField($field));

        $this->assertContains('value=5', $result);
        $this->assertContains('<input type=text', $result);

        /* A textarea field */
        $field = new Field("textarea", "A textarea field", "initial value", true, [], 1000);

        // Get result and strip quotes, for easier analysis
        $result = str_replace(['"', "'"], "", $writer->visitField($field));

        // By our current method of calculation, should have size of 100 means 10 rows
        // If change calculation, change this test
        $this->assertContains('rows=10', $result);
        $this->assertContains('<textarea', $result);
        $this->assertContains('initial value', $result);
    }
<commit_msg>Add tests for no initial text in textarea.<commit_after><?php

use UWDOEM\Framework\Field\Field;
use UWDOEM\Framework\Writer\Writer;
use UWDOEM\Framework\Form\FormAction\FormAction;
use UWDOEM\Framework\FieldBearer\FieldBearerBuilder;
use UWDOEM\Framework\Form\FormBuilder;
use UWDOEM\Framework\Section\SectionBuilder;
use UWDOEM\Framework\Page\PageBuilder;
use UWDOEM\Framework\Page\Page;


class WriterTest extends PHPUnit_Framework_TestCase
{
    public function testVisitField() {
        $writer = new Writer();

        /* A literal field */
        $field = new Field("literal", "A literal field", "initial", true, [], 200);
        $this->assertContains("initial", $writer->visitField($field));

        /* A section-label field */
        $field = new Field("section-label", "A section-label field", "initial");
        $this->assertContains("A section-label field", $writer->visitField($field));
        $this->assertNotContains("initial", $writer->visitField($field));

        /* A choice field */
        $field = new Field("choice", "A literal field", "initial", true, ["first choice", "second choice"], 200);

        $result = $writer->visitField($field);
        $this->assertContains("first choice", $result);
        $this->assertContains("second choice", $result);

        /* A multiple choice field */
        $field = new Field("multiple-choice", "A multiple-choice field", "initial", true, ["first choice", "second choice"], 200);

        $result = $writer->visitField($field);
        $this->assertContains("first choice", $result);
        $this->assertContains("second choice", $result);

        /* A text field */
        $field = new Field("text", "A text field", "5", true, [], 200);

        // Get result and strip quotes, for easier analysis
        $result = str_replace(['"', "'"], "", $writer->visitField($field));

        $this->assertContains('value=5', $result);
        $this->assertContains('<input type=text', $result);

        /* A textarea field */
        $field = new Field("textarea", "A textarea field", "initial value", true, [], 1000);

        // Get result and strip quotes, for easier analysis
        $result = str_replace(['"', "'"], "", $writer->visitField($field));

        // By our current method of calculation, should have size of 100 means 10 rows
        // If change calculation, change this test
        $this->assertContains('rows=10', $result);
        $this->assertContains('<textarea', $result);
        $this->assertContains('initial value', $result);

        /* A textarea field without an initial value*/
        $field = new Field("textarea", "A textarea field", "", true, [], 1000);

        // Get result and strip quotes, for easier analysis
        $result = str_replace(['"', "'"], "", $writer->visitField($field));

        // Assert that the text area contains no initial text
        $this->assertContains('></textarea>', $result);
    }

{'fraction_non_alphanumeric': 0.16282925032234297, 'fraction_numerical': 0.009946583164487014, 'mean_word_length': 3.265514532600157, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 45, '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': '770013', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1453, 'n_words': 414}