<commit_before><?php
/**
 * @group Form_MultiFields
 */
class Vps_Form_MultiFields_Test extends PHPUnit_Framework_TestCase
{
    protected function setUp()
    {
        parent::setUp();
        Vps_Model_Abstract::getInstance('Vps_Form_MultiFields_TestModel1')
            ->setData(array(
                array('id'=>1, 'blub'=>'blub0'),
                array('id'=>2, 'blub'=>'blub1'),
                array('id'=>3, 'blub'=>'blub2'),
            ));
        Vps_Model_Abstract::getInstance('Vps_Form_MultiFields_TestModel2')
            ->setData(array(
                array('id'=>1, 'model1_id'=>1, 'foo'=>'foo0', 'bar'=>'bar0', 'pos'=>1),
                array('id'=>2, 'model1_id'=>1, 'foo'=>'foo1', 'bar'=>'bar1', 'pos'=>2),
                array('id'=>3, 'model1_id'=>2, 'foo'=>'foo2', 'bar'=>'bar2', 'pos'=>1),
                array('id'=>4, 'model1_id'=>3, 'foo'=>'foo0', 'pos'=>1),
                array('id'=>5, 'model1_id'=>3, 'foo'=>'foo1', 'pos'=>2),
                array('id'=>6, 'model1_id'=>3, 'foo'=>'foo2', 'pos'=>3),
            ));
    }

    public function testSimple()
    {
        $m1 = new Vps_Model_FnF();
        $m2 = new Vps_Model_FnF();

        $form = new Vps_Form();
        $form->setModel($m1);
        $form->add(new Vps_Form_Field_TextField('test1'));
        $form->add(new Vps_Form_Field_MultiFields($m2))
            ->setReferences(array(
                //TODO: sollte auch mit models automatisch funktionieren
                'columns' => array('test1_id'),
                'refColumns' => array('id'),
            ))
            ->fields->add(new Vps_Form_Field_TextField('test2'));

        $post = array(
            'test1' => 'blub',
            'Vps_Model_FnF' => array(
                array('test2' => 'bab')
            )
        );
        $post = $form->processInput(null, $post);
        $form->validate(null, $post);
        $form->prepareSave(null, $post);
        $form->save(null, $post);

        $r = $m1->getRow(1);
        $this->assertEquals('blub', $r->test1);

        $r = $m2->getRow(1);
        $this->assertEquals('bab', $r->test2);
        $this->assertEquals(1, $r->test1_id);
    }

    public function testWithComplexValidate()
    {
        $m1 = new Vps_Model_FnF(array('data'=>array(
            array('id'=>1, 'test1'=>'bam')
        )));
        $m2 = new Vps_Model_FnF(array('data'=>array(
            array('id'=>1, 'test1_id'=>1, 'test2'=>'bab')
        )));

        $form = new Vps_Form();
        $form->setModel($m1);
        $form->add(new Vps_Form_Field_TextField('test1'));
        $form->add(new Vps_Form_Field_MultiFields($m2))
            ->setReferences(array(
                //TODO: sollte auch mit models automatisch funktionieren
                'columns' => array('test1_id'),
                'refColumns' => array('id'),
            ))
            ->fields->add(new Vps_Form_Field_TextField('test2'))
                    ->addValidator(new Vps_Validate_Row_Unique());;

        $post = array(
            'test1' => 'blub',
            'Vps_Model_FnF' => array(
                array('test2' => 'bab')
            )
        );
        $post = $form->processInput(null, $post);
        $this->assertEquals(1, count($form->validate(null, $post)));
    }

    public function testWithRelations()<commit_msg>todo entfernt, das funktioniert schon<commit_after><?php
/**
 * @group Form_MultiFields
 */
class Vps_Form_MultiFields_Test extends PHPUnit_Framework_TestCase
{
    protected function setUp()
    {
        parent::setUp();
        Vps_Model_Abstract::getInstance('Vps_Form_MultiFields_TestModel1')
            ->setData(array(
                array('id'=>1, 'blub'=>'blub0'),
                array('id'=>2, 'blub'=>'blub1'),
                array('id'=>3, 'blub'=>'blub2'),
            ));
        Vps_Model_Abstract::getInstance('Vps_Form_MultiFields_TestModel2')
            ->setData(array(
                array('id'=>1, 'model1_id'=>1, 'foo'=>'foo0', 'bar'=>'bar0', 'pos'=>1),
                array('id'=>2, 'model1_id'=>1, 'foo'=>'foo1', 'bar'=>'bar1', 'pos'=>2),
                array('id'=>3, 'model1_id'=>2, 'foo'=>'foo2', 'bar'=>'bar2', 'pos'=>1),
                array('id'=>4, 'model1_id'=>3, 'foo'=>'foo0', 'pos'=>1),
                array('id'=>5, 'model1_id'=>3, 'foo'=>'foo1', 'pos'=>2),
                array('id'=>6, 'model1_id'=>3, 'foo'=>'foo2', 'pos'=>3),
            ));
    }

    public function testSimple()
    {
        $m1 = new Vps_Model_FnF();
        $m2 = new Vps_Model_FnF();

        $form = new Vps_Form();
        $form->setModel($m1);
        $form->add(new Vps_Form_Field_TextField('test1'));
        $form->add(new Vps_Form_Field_MultiFields($m2))
            ->setReferences(array(
                'columns' => array('test1_id'),
                'refColumns' => array('id'),
            ))
            ->fields->add(new Vps_Form_Field_TextField('test2'));

        $post = array(
            'test1' => 'blub',
            'Vps_Model_FnF' => array(
                array('test2' => 'bab')
            )
        );
        $post = $form->processInput(null, $post);
        $form->validate(null, $post);
        $form->prepareSave(null, $post);
        $form->save(null, $post);

        $r = $m1->getRow(1);
        $this->assertEquals('blub', $r->test1);

        $r = $m2->getRow(1);
        $this->assertEquals('bab', $r->test2);
        $this->assertEquals(1, $r->test1_id);
    }

    public function testWithComplexValidate()
    {
        $m1 = new Vps_Model_FnF(array('data'=>array(
            array('id'=>1, 'test1'=>'bam')
        )));
        $m2 = new Vps_Model_FnF(array('data'=>array(
            array('id'=>1, 'test1_id'=>1, 'test2'=>'bab')
        )));

        $form = new Vps_Form();
        $form->setModel($m1);
        $form->add(new Vps_Form_Field_TextField('test1'));
        $form->add(new Vps_Form_Field_MultiFields($m2))
            ->setReferences(array(
                'columns' => array('test1_id'),
                'refColumns' => array('id'),
            ))
            ->fields->add(new Vps_Form_Field_TextField('test2'))
                    ->addValidator(new Vps_Validate_Row_Unique());;

        $post = array(
            'test1' => 'blub',
            'Vps_Model_FnF' => array(
                array('test2' => 'bab')
            )
        );
        $post = $form->processInput(null, $post);
        $this->assertEquals(1, count($form->validate(null, $post)));
    }

    public function testWithRelations()
{'fraction_non_alphanumeric': 0.19535098522167488, 'fraction_numerical': 0.022783251231527094, 'mean_word_length': 2.1523532265890344, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 163, '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': '111135', 'n_tokens_mistral': 2159, 'n_tokens_neox': 2128, 'n_words': 311}