<?php

namespace KupShop\I18nBundle\Tests;

use KupShop\KupShopBundle\Config;

class LanguageAwareRouterSKTest extends \DatabaseTestCase
{
    public function setUp(): void
    {
        parent::setUp();

        $this->deleteTmpFile('router_sk/url_generating_routes.php');
        $this->deleteTmpFile('router_sk/url_matching_routes.php');

        $this->switchLanguage();
    }

    public function testSKPath()
    {
        $this->assertEquals('/vyrobcovia/', path('kupshop_catalog_producer_list'));
    }

    public function testSkUrlGenerator()
    {
        $client = static::createClient();
        $client->request('GET', '/vyrobcovia/');

        $cfg = Config::get();
        $this->assertFileExists($cfg['Path']['data'].'tmp/test_engine/router_cs/url_generating_routes.php');
        $this->assertFileExists($cfg['Path']['data'].'tmp/test_engine/router_cs/url_matching_routes.php');
    }

    private function deleteTmpFile($file)
    {
        $cfg = Config::get();
        $path = $cfg['Path']['data'].'tmp/test_engine/';
        if (file_exists($path.$file)) {
            unlink($path.$file);
        }
    }
}
