<commit_before><?php

/**
 * This file is part of the PHP ST utility.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Zikula\Tools\Tests\Converter;

use Zikula\Tools\Converter;

/**
 * @author craig
 */
class ZikulaConverterTest extends \PHPUnit_Framework_TestCase
{
    protected $converter;

    public function setUp()
    {
        $this->converter = new Converter\ZikulaConverter();
    }

    /**
     * @covers       Zikula\Tools\Converter\ZikulaConverter::convert
     * @dataProvider Provider
     */
    public function testThatZikulaIsConverted($smarty, $twig)
    {
        $this->assertSame($twig,
            $this->converter->convert($this->getFileMock(), $smarty)
        );

    }

    public function Provider()
    {
        return [
            // test \Zikula\Tools\Converter\ZikulaConverter::replaceBlockPosition
            ["{blockposition name=left}", "{{ showblockposition('left') }}"],
            ["{blockposition name='left'}", "{{ showblockposition('left') }}"],
            ["{blockposition name=\"left\"}", "{{ showblockposition('left') }}"],
            ["{blockposition name=topnav assign=topnavblock}", "{% set topnavblock = showblockposition('topnav') %}"],
            ["{blockposition name=topnav assign='topnavblock'}", "{% set topnavblock = showblockposition('topnav') %}"],
            ["{blockposition name=topnav assign=\"topnavblock\"}", "{% set topnavblock = showblockposition('topnav') %}"],

            // test \Zikula\Tools\Converter\ZikulaConverter::replaceModurl
            ["{modurl modname='ZikulaSettingsModule' type='admin' func='index'}", "{{ path('zikulasettingsmodule_admin_index') }}"],
            [
                "{modurl modname='ZikulaSettingsModule' type='admin' func='index' foo='bar'}",
                "{{ path('zikulasettingsmodule_admin_index', {\"foo\":\"bar\"}) }}"
            ],
            [
                "{modurl modname='ZikulaSettingsModule' type='admin' func='index' foo='bar' boo=far}",
                "{{ path('zikulasettingsmodule_admin_index', {\"foo\":\"bar\",\"boo\":\"far\"}) }}"
            ],
            [
                "{modurl modname='ZikulaSettingsModule' type='admin' func='index' foo='bar' boo=\$far}",
                "{{ path('zikulasettingsmodule_admin_index', {\"foo\":\"bar\",\"boo\":\"far\"}) }}"
            ],
            [
                "{modurl modname='ZikulaSettingsModule' type='admin' func='index' assign='foo'}",
                "{% set foo = path('zikulasettingsmodule_admin_index') %}"
            ],

            // test \Zikula\Tools\Converter\ZikulaConverter::replaceRoute
            ["{route name='zikulaadminmodule_admin_newcat'}", "{{ path('zikulaadminmodule_admin_newcat') }}"],
            ["{route name=\"zikulaadminmodule_admin_newcat\"}", "{{ path('zikulaadminmodule_admin_newcat') }}"],
            ["{route name='zikulaadminmodule_admin_newcat' foo='bar'}", "{{ path('zikulaadminmodule_admin_newcat', {\"foo\":\"bar\"}) }}"],
            [
                "{route name='zikulaadminmodule_admin_newcat' foo='bar' assign='foo'}",
                "{% set foo = path('zikulaadminmodule_admin_newcat', {\"foo\":\"bar\"}) %}"
            ],

            // test \Zikula\Tools\Converter\ZikulaConverter::replacePageaddvar
            [
                "{pageaddvar name=\"stylesheet\" value=\"\$stylepath/style.css\"}",
                "{{ pageAddVar('stylesheet', '') }}{# @todo oldpath= \$stylepath/style.css to @VendorBundleTheme:path/from/Resources #}"
            ],
            [
                "{pageaddvar name='stylesheet' value=\$stylepath/style.css}",
                "{{ pageAddVar('stylesheet', '') }}{# @todo oldpath= \$stylepath/style.css to @VendorBundleTheme:path/from/Resources #}"
            ],

            // test \Zikula\Tools\Converter\ZikulaConverter::replaceGettext
            ["{gt text='foo'}", "{{ __('foo') }}"],
            [
                "{gt text='Membership application' assign='templatetitle'}",
                "{% set templatetitle = __('Membership application') %}"
            ],
            [
                "{gt text='Delete: %s' tag1=\$group.name'}",
                "{{ __f('Delete: %sub%', {\"%sub%\": group.name}) }}"
            ],
            [
                "{gt text='Delete: %s' tag1=\$group.name assign='strDeleteGroup'}",
                "{% set strDeleteGroup = __f('Delete: %sub%', {\"%sub%\": group.name}) %}"
            ],

            // test \Zikula\Tools\Converter\ZikulaConverter::replaceCheckPermission
            [
                "{checkpermission component='ZikulaUsersModule::' instance=\"::\" level='ACCESS_MODERATE'}",
                "{{ hasPermission('ZikulaUsersModule::', '::', 'ACCESS_MODERATE') }}{# @todo consider `if hasPermission()` #}"
            ],
            [
                "{checkpermission component=ZikulaUsersModule:: instance='::' level=ACCESS_MODERATE}",
                "{{ hasPermission('ZikulaUsersModule::', '::', 'ACCESS_MODERATE') }}{# @todo consider `if hasPermission()` #}"
            ],
            [
                "{checkpermission component='ZikulaUsersModule::' instance=\"::\" level='ACCESS_MODERATE' assign='foo'}",
                "{% set foo = hasPermission('ZikulaUsersModule::', '::', 'ACCESS_MODERATE') %}{# @todo consider `if hasPermission()` #}"
            ],

            // test \Zikula\Tools\Converter\ZikulaConverter::replaceCheckPermissionBlock
            [
                "{checkpermissionblock component='ZikulaUsersModule::' instance=\"::\" level='ACCESS_MODERATE'}",
                "{% if hasPermission('ZikulaUsersModule::', '::', 'ACCESS_MODERATE') %}"
            ],
            [
                "{checkpermissionblock component=ZikulaUsersModule:: instance='::' level=ACCESS_MODERATE}",
                "{% if hasPermission('ZikulaUsersModule::', '::', 'ACCESS_MODERATE') %}"
            ],

            // test \Zikula\Tools\Converter\ZikulaConverter::replaceEmptyTest
            ["if !empty(title)", "if title is not empty"],

            // test \Zikula\Tools\Converter\ZikulaConverter::replaceAjaxHeader
            ["{ajaxheader modname='Groups' filename='groups.js' ui=true}", "{# ajaxheader modname='Groups' filename='groups.js' ui=true #}"],

            // test \Zikula\Tools\Converter\ZikulaConverter::replaceModvarLookup
            ["modvars.ZikulaGroupsModule.hideclosed", "{{ getModVar('ZikulaGroupsModule', 'hideclosed') }}"],
            ["modvars.ZConfig.sitename", "{{ getModVar('ZConfig', 'sitename') }}"],
        ];
    }

    /**
     * @covers Zikula\Tools\Converter\ZikulaConverter::getName
     */
    public function testThatHaveExpectedName()
    {
        $this->assertEquals('zikula', $this->converter->getName());
    }

    /**
     * @covers Zikula\Tools\Converter\Zikulaconverter::getDescription
     */
    public function testThatHaveDescription()
    {
        $this->assertNotEmpty($this->converter->getDescription());
    }

    private function getFileMock()
    {<commit_msg>add extraneous texts to tests<commit_after><?php

/**
 * This file is part of the PHP ST utility.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Zikula\Tools\Tests\Converter;

use Zikula\Tools\Converter;

/**
 * @author craig
 */
class ZikulaConverterTest extends \PHPUnit_Framework_TestCase
{
    protected $converter;

    public function setUp()
    {
        $this->converter = new Converter\ZikulaConverter();
    }

    /**
     * @covers       Zikula\Tools\Converter\ZikulaConverter::convert
     * @dataProvider Provider
     */
    public function testThatZikulaIsConverted($smarty, $twig)
    {
        $this->assertSame($twig,
            $this->converter->convert($this->getFileMock(), $smarty)
        );

    }

    public function Provider()
    {
        return [
            // test \Zikula\Tools\Converter\ZikulaConverter::replaceBlockPosition
            ["123{blockposition name=left}321", "123{{ showblockposition('left') }}321"],
            ["123{blockposition name='left'}321", "123{{ showblockposition('left') }}321"],
            ["123{blockposition name=\"left\"}321", "123{{ showblockposition('left') }}321"],
            ["123{blockposition name=topnav assign=topnavblock}321", "123{% set topnavblock = showblockposition('topnav') %}321"],
            ["123{blockposition name=topnav assign='topnavblock'}321", "123{% set topnavblock = showblockposition('topnav') %}321"],
            ["123{blockposition name=topnav assign=\"topnavblock\"}321", "123{% set topnavblock = showblockposition('topnav') %}321"],

            // test \Zikula\Tools\Converter\ZikulaConverter::replaceModurl
            ["123{modurl modname='ZikulaSettingsModule' type='admin' func='index'}321", "123{{ path('zikulasettingsmodule_admin_index') }}321"],
            [
                "123{modurl modname='ZikulaSettingsModule' type='admin' func='index' foo='bar'}321",
                "123{{ path('zikulasettingsmodule_admin_index', {\"foo\":\"bar\"}) }}321"
            ],
            [
                "123{modurl modname='ZikulaSettingsModule' type='admin' func='index' foo='bar' boo=far}321",
                "123{{ path('zikulasettingsmodule_admin_index', {\"foo\":\"bar\",\"boo\":\"far\"}) }}321"
            ],
            [
                "123{modurl modname='ZikulaSettingsModule' type='admin' func='index' foo='bar' boo=\$far}321",
                "123{{ path('zikulasettingsmodule_admin_index', {\"foo\":\"bar\",\"boo\":\"far\"}) }}321"
            ],
            [
                "123{modurl modname='ZikulaSettingsModule' type='admin' func='index' assign='foo'}321",
                "123{% set foo = path('zikulasettingsmodule_admin_index') %}321"
            ],

            // test \Zikula\Tools\Converter\ZikulaConverter::replaceRoute
            ["123{route name='zikulaadminmodule_admin_newcat'}321", "123{{ path('zikulaadminmodule_admin_newcat') }}321"],
            ["123{route name=\"zikulaadminmodule_admin_newcat\"}321", "123{{ path('zikulaadminmodule_admin_newcat') }}321"],
            ["123{route name='zikulaadminmodule_admin_newcat' foo='bar'}321", "123{{ path('zikulaadminmodule_admin_newcat', {\"foo\":\"bar\"}) }}321"],
            [
                "123{route name='zikulaadminmodule_admin_newcat' foo='bar' assign='foo'}321",
                "123{% set foo = path('zikulaadminmodule_admin_newcat', {\"foo\":\"bar\"}) %}321"
            ],

            // test \Zikula\Tools\Converter\ZikulaConverter::replacePageaddvar
            [
                "123{pageaddvar name=\"stylesheet\" value=\"\$stylepath/style.css\"}321",
                "123{{ pageAddVar('stylesheet', '') }}{# @todo oldpath= \$stylepath/style.css to @VendorBundleTheme:path/from/Resources #}321"
            ],
            [
                "123{pageaddvar name='stylesheet' value=\$stylepath/style.css}321",
                "123{{ pageAddVar('stylesheet', '') }}{# @todo oldpath= \$stylepath/style.css to @VendorBundleTheme:path/from/Resources #}321"
            ],

            // test \Zikula\Tools\Converter\ZikulaConverter::replaceGettext
            ["123{gt text='foo'}321", "123{{ __('foo') }}321"],
            [
                "123{gt text='Membership application' assign='templatetitle'}321",
                "123{% set templatetitle = __('Membership application') %}321"
            ],
            [
                "123{gt text='Delete: %s' tag1=\$group.name'}321",
                "123{{ __f('Delete: %sub%', {\"%sub%\": group.name}) }}321"
            ],
            [
                "123{gt text='Delete: %s' tag1=\$group.name assign='strDeleteGroup'}321",
                "123{% set strDeleteGroup = __f('Delete: %sub%', {\"%sub%\": group.name}) %}321"
            ],

            // test \Zikula\Tools\Converter\ZikulaConverter::replaceCheckPermission
            [
                "123{checkpermission component='ZikulaUsersModule::' instance=\"::\" level='ACCESS_MODERATE'}321",
                "123{{ hasPermission('ZikulaUsersModule::', '::', 'ACCESS_MODERATE') }}{# @todo consider `if hasPermission()` #}321"
            ],
            [
                "123{checkpermission component=ZikulaUsersModule:: instance='::' level=ACCESS_MODERATE}321",
                "123{{ hasPermission('ZikulaUsersModule::', '::', 'ACCESS_MODERATE') }}{# @todo consider `if hasPermission()` #}321"
            ],
            [
                "123{checkpermission component='ZikulaUsersModule::' instance=\"::\" level='ACCESS_MODERATE' assign='foo'}321",
                "123{% set foo = hasPermission('ZikulaUsersModule::', '::', 'ACCESS_MODERATE') %}{# @todo consider `if hasPermission()` #}321"
            ],

            // test \Zikula\Tools\Converter\ZikulaConverter::replaceCheckPermissionBlock
            [
                "123{checkpermissionblock component='ZikulaUsersModule::' instance=\"::\" level='ACCESS_MODERATE'}321",
                "123{% if hasPermission('ZikulaUsersModule::', '::', 'ACCESS_MODERATE') %}321"
            ],
            [
                "123{checkpermissionblock component=ZikulaUsersModule:: instance='::' level=ACCESS_MODERATE}321",
                "123{% if hasPermission('ZikulaUsersModule::', '::', 'ACCESS_MODERATE') %}321"
            ],

            // test \Zikula\Tools\Converter\ZikulaConverter::replaceEmptyTest
            ["123if !empty(title)321", "123if title is not empty321"],

            // test \Zikula\Tools\Converter\ZikulaConverter::replaceAjaxHeader
            ["123{ajaxheader modname='Groups' filename='groups.js' ui=true}321", "123{# ajaxheader modname='Groups' filename='groups.js' ui=true #}321"],

            // test \Zikula\Tools\Converter\ZikulaConverter::replaceModvarLookup
            ["modvars.ZikulaGroupsModule.hideclosed", "{{ getModVar('ZikulaGroupsModule', 'hideclosed') }}"],
            ["modvars.ZConfig.sitename", "{{ getModVar('ZConfig', 'sitename') }}"],
        ];
    }

    /**
     * @covers Zikula\Tools\Converter\ZikulaConverter::getName
     */
    public function testThatHaveExpectedName()
    {
        $this->assertEquals('zikula', $this->converter->getName());
    }

    /**
     * @covers Zikula\Tools\Converter\Zikulaconverter::getDescription
     */
    public function testThatHaveDescription()
    {
        $this->assertNotEmpty($this->converter->getDescription());
    }

    private function getFileMock()
    {
{'fraction_non_alphanumeric': 0.17216721672167218, 'fraction_numerical': 0.023377337733773377, 'mean_word_length': 2.6462772624717976, 'pattern_counts': {'":': 24, '<': 11, '<?xml version=': 0, '>': 31, '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': '3092190', 'n_tokens_mistral': 4562, 'n_tokens_neox': 4207, 'n_words': 658}