<commit_before>#!/usr/bin/perl

use strict;
use warnings;

use Test::More;
use Test::FailWarnings;
use Test::Exception;
use BOM::View::Form;
use BOM::View::Form::Select;

my $form_obj;

{
    $form_obj = create_form_object();

    # Test set_field_value and get_field_value
    $form_obj->set_field_value('amount', 100);
    Test::More::is($form_obj->get_field_value('amount'), 100, 'Test accessor of fields of form object. [set_field_value, get_field_value]');

    # Test set_field_value and get_field_value [before select]
    Test::More::is($form_obj->get_field_value('gender'),
        'male', 'Test accessor of fields of form object [Select - male]. [set_field_value, get_field_value]');

    # Test set_field_value and get_field_value
    $form_obj->set_field_value('gender', 'female');
    Test::More::is($form_obj->get_field_value('gender'),
        'female', 'Test accessor of fields of form object [Select - female]. [set_field_value, get_field_value]');

    # Test set_field_value and get_field_value
    $form_obj->set_field_value('select_text_curr', 'EUR');
    Test::More::is($form_obj->get_field_value('select_text_curr'),
        'EUR', 'Test accessor of array fields of form object [Select - EUR]. [set_field_value, get_field_value]');

    # Test set_field_value and get_field_value
    Test::More::is($form_obj->get_field_value('select_text_amount'),
        20, 'Test accessor of array fields of form object [text - 20(default value)]. [set_field_value, get_field_value]');
    # Test set_field_value and get_field_value
    $form_obj->set_field_value('select_text_amount', 50);
    Test::More::is($form_obj->get_field_value('select_text_amount'),
        50, 'Test accessor of array fields of form object [text - 50]. [set_field_value, get_field_value]');

    # Test set_field_value and get_field_value
    Test::More::is(
        $form_obj->get_field_value('Textarea'),
        'This is default value of textarea',
        'Test accessor of fields of form object [textarea - \'This is default value of textarea\'(default value)]. [set_field_value, get_field_value]'
    );
    # Test set_field_value and get_field_value
    $form_obj->set_field_value('Textarea', 'It should be changed now...');
    Test::More::is(
        $form_obj->get_field_value('Textarea'),
        'It should be changed now...',
        'Test accessor of fields of form object [text - \'It should be changed now...\']. [set_field_value, get_field_value]'
    );

    # Test set_field_value and get_field_value
    Test::More::is($form_obj->get_field_value('Password'),
        '<PASSWORD>rd', 'Test accessor of fields of form object [password - <PASSWORD>(default value)]. [set_field_value, get_field_value]');
    # Test set_field_value and get_field_value
    $form_obj->set_field_value('Password', '<PASSWORD>');
    Test::More::is($form_obj->get_field_value('Password'),
        'Baghali', 'Test accessor of fields of form object [password - Baghali]. [set_field_value, get_field_value]');

    # Test set_field_value and get_field_value
    Test::More::is($form_obj->get_field_value('single_checkbox'),
        undef, 'Test accessor of fields of form object [single_checkbox - (Not checked)]. [set_field_value, get_field_value]');
    # Test set_field_value and get_field_value
    $form_obj->set_field_value('single_checkbox', 'SGLBOX');
    Test::More::is($form_obj->get_field_value('single_checkbox'),
        'SGLBOX', 'Test accessor of fields of form object [single_checkbox - SGLBOX]. [set_field_value, get_field_value]');

    # Test set_field_value and get_field_value
    Test::More::is($form_obj->get_field_value('checkbox1'),
        undef, 'Test accessor of fields of form object [checkbox1 - (Not checked)]. [set_field_value, get_field_value]');
    Test::More::is($form_obj->get_field_value('checkbox2'),
        undef, 'Test accessor of fields of form object [checkbox2 - (Not checked)]. [set_field_value, get_field_value]');
    # Test set_field_value and get_field_value
    $form_obj->set_field_value('checkbox1', 'BOX1');
    $form_obj->set_field_value('checkbox2', 'BOX2');
    Test::More::is($form_obj->get_field_value('checkbox1'),
        'BOX1', 'Test accessor of fields of form object [checkbox1 - BOX1]. [set_field_value, get_field_value]');
    Test::More::is($form_obj->get_field_value('checkbox2'),
        'BOX2', 'Test accessor of fields of form object [checkbox2 - BOX2]. [set_field_value, get_field_value]');

    # Test set_field_error_message
    $form_obj->set_field_error_message('amount', 'It is not good');
    Test::More::is(
        $form_obj->get_field_error_message('amount'),
        'It is not good',
        'Test accessor of fields of form object. [set_field_error_message, get_field_error_message]'
    );

    # Test set_field_error_message
    $form_obj->set_field_error_message('error_general', 'There is a general error.');
    Test::More::is(
        $form_obj->get_field_error_message('error_general'),
        'There is a general error.',
        'Test accessor of general error of form object . [set_field_error_message, get_field_error_message]'
    );

}

sub create_form_object {
    my $form_obj;

    # Form attributes require to create new form object
    my $form_attributes = {
        'name'   => 'name_test_form',
        'id'     => 'id_test_form',
        'method' => 'post',
        'action' => 'http://localhost/some/where/test.cgi',
        'class'  => 'formObject',
    };

    # Create new form object
    Test::Exception::lives_ok { $form_obj = BOM::View::Form->new($form_attributes); } 'Create Form';

    # Test object type
    Test::More::isa_ok($form_obj, 'BOM::View::Form');

    my $fieldset_index = $form_obj->add_fieldset({});

    my $input_field_amount = {
        'label' => {
            'text'     => 'Amount',
            'for'      => 'amount',
            'optional' => '0',
        },
        'input' => {
            'type'      => 'text',
            'id'        => 'amount',
            'name'      => 'amount',
            'maxlength' => 40,
            'value'     => '',
        },
        'error' => {
            'text'  => '',
            'id'    => 'error_amount',
            'class' => 'errorfield',
        },
        'validation' => [{
                'type'    => 'regexp',
                'regexp'  => '\w+',
                'err_msg' => 'Not empty',
            },
            {
                'type'    => 'regexp',
                'regexp'  => '\d+',
                'err_msg' => 'Must be digit',
            },
            {
                'type'    => 'min_amount',
                'amount'  => 50,
                'err_msg' => 'Too little',
            },
            {
                'type'    => 'max_amount',
                'amount'  => 500,
                'err_msg' => 'Too much',
            },
            {
                'type'     => 'custom',
                'function' => 'custom_amount_validation()',
                'err_msg'  => 'It is not good',
            }
        ],
    };

    my $input_field_gender = {
        'label' => {
            'text'     => 'gender',
            'for'      => 'gender',
            'optional' => '0',
        },
        'input' => BOM::View::Form::Select->new(
            'id'      => 'gender',
            'name'    => 'gender',
            'options' => [{value => 'male'}, {value => 'female'}],
            'values'  => ['male'],
        ),
        'error' => {
            'text'  => '',
            'id'    => 'error_gender',
            'class' => 'errorfield',
        },
    };

    my $select_curr = BOM::View::Form::Select->new(
        'id'      => 'select_text_curr',
        'name'    => 'select_text_curr',
        'options' => [{value => 'USD'}, {value => "EUR"}],
    );
    my $input_amount = {
        'id'    => 'select_text_amount',
        'name'  => 'select_text_amount',
        'type'  => 'text',
        'value' => '20'
    };
    my $input_field_select_text = {
        'label' => {
            'text'     => 'select_text',
            'for'      => 'select_text',
            'optional' => '0',
        },
        'input' => [$select_curr, $input_amount],
        'error' => {
            'text'  => '',
            'id'    => 'error_select_text',
            'class' => 'errorfield',<commit_msg>test pass<commit_after>#!/usr/bin/perl

use strict;
use warnings;

use Test::More;
use Test::FailWarnings;
use Test::Exception;
use HTML::FormBuilder;
use HTML::FormBuilder::Select;

my $form_obj;

{
    $form_obj = create_form_object();

    # Test set_field_value and get_field_value
    $form_obj->set_field_value('amount', 100);
    Test::More::is($form_obj->get_field_value('amount'), 100, 'Test accessor of fields of form object. [set_field_value, get_field_value]');

    # Test set_field_value and get_field_value [before select]
    Test::More::is($form_obj->get_field_value('gender'),
        'male', 'Test accessor of fields of form object [Select - male]. [set_field_value, get_field_value]');

    # Test set_field_value and get_field_value
    $form_obj->set_field_value('gender', 'female');
    Test::More::is($form_obj->get_field_value('gender'),
        'female', 'Test accessor of fields of form object [Select - female]. [set_field_value, get_field_value]');

    # Test set_field_value and get_field_value
    $form_obj->set_field_value('select_text_curr', 'EUR');
    Test::More::is($form_obj->get_field_value('select_text_curr'),
        'EUR', 'Test accessor of array fields of form object [Select - EUR]. [set_field_value, get_field_value]');

    # Test set_field_value and get_field_value
    Test::More::is($form_obj->get_field_value('select_text_amount'),
        20, 'Test accessor of array fields of form object [text - 20(default value)]. [set_field_value, get_field_value]');
    # Test set_field_value and get_field_value
    $form_obj->set_field_value('select_text_amount', 50);
    Test::More::is($form_obj->get_field_value('select_text_amount'),
        50, 'Test accessor of array fields of form object [text - 50]. [set_field_value, get_field_value]');

    # Test set_field_value and get_field_value
    Test::More::is(
        $form_obj->get_field_value('Textarea'),
        'This is default value of textarea',
        'Test accessor of fields of form object [textarea - \'This is default value of textarea\'(default value)]. [set_field_value, get_field_value]'
    );
    # Test set_field_value and get_field_value
    $form_obj->set_field_value('Textarea', 'It should be changed now...');
    Test::More::is(
        $form_obj->get_field_value('Textarea'),
        'It should be changed now...',
        'Test accessor of fields of form object [text - \'It should be changed now...\']. [set_field_value, get_field_value]'
    );

    # Test set_field_value and get_field_value
    Test::More::is($form_obj->get_field_value('Password'),
        '<PASSWORD>', 'Test accessor of fields of form object [password - <PASSWORD>(default value)]. [set_field_value, get_field_value]');
    # Test set_field_value and get_field_value
    $form_obj->set_field_value('Password', '<PASSWORD>');
    Test::More::is($form_obj->get_field_value('Password'),
        'Baghali', 'Test accessor of fields of form object [password - Baghali]. [set_field_value, get_field_value]');

    # Test set_field_value and get_field_value
    Test::More::is($form_obj->get_field_value('single_checkbox'),
        undef, 'Test accessor of fields of form object [single_checkbox - (Not checked)]. [set_field_value, get_field_value]');
    # Test set_field_value and get_field_value
    $form_obj->set_field_value('single_checkbox', 'SGLBOX');
    Test::More::is($form_obj->get_field_value('single_checkbox'),
        'SGLBOX', 'Test accessor of fields of form object [single_checkbox - SGLBOX]. [set_field_value, get_field_value]');

    # Test set_field_value and get_field_value
    Test::More::is($form_obj->get_field_value('checkbox1'),
        undef, 'Test accessor of fields of form object [checkbox1 - (Not checked)]. [set_field_value, get_field_value]');
    Test::More::is($form_obj->get_field_value('checkbox2'),
        undef, 'Test accessor of fields of form object [checkbox2 - (Not checked)]. [set_field_value, get_field_value]');
    # Test set_field_value and get_field_value
    $form_obj->set_field_value('checkbox1', 'BOX1');
    $form_obj->set_field_value('checkbox2', 'BOX2');
    Test::More::is($form_obj->get_field_value('checkbox1'),
        'BOX1', 'Test accessor of fields of form object [checkbox1 - BOX1]. [set_field_value, get_field_value]');
    Test::More::is($form_obj->get_field_value('checkbox2'),
        'BOX2', 'Test accessor of fields of form object [checkbox2 - BOX2]. [set_field_value, get_field_value]');

    # Test set_field_error_message
    $form_obj->set_field_error_message('amount', 'It is not good');
    Test::More::is(
        $form_obj->get_field_error_message('amount'),
        'It is not good',
        'Test accessor of fields of form object. [set_field_error_message, get_field_error_message]'
    );

    # Test set_field_error_message
    $form_obj->set_field_error_message('error_general', 'There is a general error.');
    Test::More::is(
        $form_obj->get_field_error_message('error_general'),
        'There is a general error.',
        'Test accessor of general error of form object . [set_field_error_message, get_field_error_message]'
    );

}

sub create_form_object {
    my $form_obj;

    # Form attributes require to create new form object
    my $form_attributes = {
        'name'   => 'name_test_form',
        'id'     => 'id_test_form',
        'method' => 'post',
        'action' => 'http://localhost/some/where/test.cgi',
        'class'  => 'formObject',
    };

    # Create new form object
    Test::Exception::lives_ok { $form_obj = HTML::FormBuilder->new($form_attributes); } 'Create Form';

    # Test object type
    Test::More::isa_ok($form_obj, 'HTML::FormBuilder');

    my $fieldset_index = $form_obj->add_fieldset({});

    my $input_field_amount = {
        'label' => {
            'text'     => 'Amount',
            'for'      => 'amount',
            'optional' => '0',
        },
        'input' => {
            'type'      => 'text',
            'id'        => 'amount',
            'name'      => 'amount',
            'maxlength' => 40,
            'value'     => '',
        },
        'error' => {
            'text'  => '',
            'id'    => 'error_amount',
            'class' => 'errorfield',
        },
        'validation' => [{
                'type'    => 'regexp',
                'regexp'  => '\w+',
                'err_msg' => 'Not empty',
            },
            {
                'type'    => 'regexp',
                'regexp'  => '\d+',
                'err_msg' => 'Must be digit',
            },
            {
                'type'    => 'min_amount',
                'amount'  => 50,
                'err_msg' => 'Too little',
            },
            {
                'type'    => 'max_amount',
                'amount'  => 500,
                'err_msg' => 'Too much',
            },
            {
                'type'     => 'custom',
                'function' => 'custom_amount_validation()',
                'err_msg'  => 'It is not good',
            }
        ],
    };

    my $input_field_gender = {
        'label' => {
            'text'     => 'gender',
            'for'      => 'gender',
            'optional' => '0',
        },
        'input' => HTML::FormBuilder::Select->new(
            'id'      => 'gender',
            'name'    => 'gender',
            'options' => [{value => 'male'}, {value => 'female'}],
            'values'  => ['male'],
        ),
        'error' => {
            'text'  => '',
            'id'    => 'error_gender',
            'class' => 'errorfield',
        },
    };

    my $select_curr = HTML::FormBuilder::Select->new(
        'id'      => 'select_text_curr',
        'name'    => 'select_text_curr',
        'options' => [{value => 'USD'}, {value => "EUR"}],
    );
    my $input_amount = {
        'id'    => 'select_text_amount',
        'name'  => 'select_text_amount',
        'type'  => 'text',
        'value' => '20'
    };
    my $input_field_select_text = {
        'label' => {
            'text'     => 'select_text',
            'for'      => 'select_text',
            'optional' => '0',
        },
        'input' => [$select_curr, $input_amount],
        'error' => {
            'text'  => '',
            'id'    => 'error_select_text',
            'class' => 'errorfield',
{'fraction_non_alphanumeric': 0.1523625843780135, 'fraction_numerical': 0.005303760848601736, 'mean_word_length': 2.569922547332186, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 211, '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': '5157221', 'n_tokens_mistral': 5354, 'n_tokens_neox': 5194, 'n_words': 1108}