<commit_before><?php

/**
 * This file is part of CodeIgniter 4 framework.
 *
 * (c) CodeIgniter Foundation <<EMAIL>>
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace CodeIgniter\Helpers;

use CodeIgniter\HTTP\URI;
use CodeIgniter\Test\CIUnitTestCase;
use Config\App;
use Config\Filters;
use Config\Services;

/**
 * @internal
 *
 * @group SeparateProcess
 */
final class FormHelperTest extends CIUnitTestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        helper('form');

        $this->resetServices();
    }

    private function setRequest(): void
    {
        $uri = new URI('http://example.com/');
        Services::injectMock('uri', $uri);

        $config            = new App();
        $config->baseURL   = '';
        $config->indexPage = 'index.php';

        $request = Services::request($config);
        Services::injectMock('request', $request);
    }

    public function testFormOpenBasic()
    {
        $request = $this->setRequest();
        Services::injectMock('request', $request);

        $before = (new Filters())->globals['before'];
        if (in_array('csrf', $before, true) || array_key_exists('csrf', $before)) {
            $Value    = csrf_hash();
            $Name     = csrf_token();
            $expected = <<<EOH
                <form action="http://example.com/index.php/foo/bar" name="form" id="form" method="POST" accept-charset="utf-8">
                <input type="hidden" name="{$Name}" value="{$Value}" style="display:none;" />

                EOH;
        } else {
            $expected = <<<'EOH'
                <form action="http://example.com/index.php/foo/bar" name="form" id="form" method="POST" accept-charset="utf-8">

                EOH;
        }

        $attributes = [
            'name'   => 'form',
            'id'     => 'form',
            'method' => 'POST',
        ];<commit_msg>test: remove uneeded code<commit_after><?php

/**
 * This file is part of CodeIgniter 4 framework.
 *
 * (c) CodeIgniter Foundation <<EMAIL>>
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace CodeIgniter\Helpers;

use CodeIgniter\HTTP\URI;
use CodeIgniter\Test\CIUnitTestCase;
use Config\App;
use Config\Filters;
use Config\Services;

/**
 * @internal
 *
 * @group SeparateProcess
 */
final class FormHelperTest extends CIUnitTestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        helper('form');

        $this->resetServices();
    }

    private function setRequest(): void
    {
        $uri = new URI('http://example.com/');
        Services::injectMock('uri', $uri);

        $config            = new App();
        $config->baseURL   = '';
        $config->indexPage = 'index.php';

        $request = Services::request($config);
        Services::injectMock('request', $request);
    }

    public function testFormOpenBasic()
    {
        $this->setRequest();

        $before = (new Filters())->globals['before'];
        if (in_array('csrf', $before, true) || array_key_exists('csrf', $before)) {
            $Value    = csrf_hash();
            $Name     = csrf_token();
            $expected = <<<EOH
                <form action="http://example.com/index.php/foo/bar" name="form" id="form" method="POST" accept-charset="utf-8">
                <input type="hidden" name="{$Name}" value="{$Value}" style="display:none;" />

                EOH;
        } else {
            $expected = <<<'EOH'
                <form action="http://example.com/index.php/foo/bar" name="form" id="form" method="POST" accept-charset="utf-8">

                EOH;
        }

        $attributes = [
            'name'   => 'form',
            'id'     => 'form',
            'method' => 'POST',
        ];
{'fraction_non_alphanumeric': 0.15873015873015872, 'fraction_numerical': 0.0015360983102918587, 'mean_word_length': 2.250415973377704, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, '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': '7045338', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1128, 'n_words': 258}