Files
kupshop/bundles/KupShop/KupShopBundle/Tests/CreateUrlTest.php
2025-08-02 16:30:27 +02:00

104 lines
3.1 KiB
PHP

<?php
namespace KupShop\KupShopBundle\Tests;
use KupShop\KupShopBundle\Context\LanguageContext;
use KupShop\KupShopBundle\Util\System\UrlFinder;
class CreateUrlTest extends \DatabaseTestCase
{
/** @var LanguageContext */
private $languageContext;
/** @var UrlFinder */
private $urlFinder;
protected function setUp(): void
{
parent::setUp();
$this->languageContext = $this->get(LanguageContext::class);
$this->urlFinder = $this->get(UrlFinder::class);
// Set CDN but do not activate
\Settings::getDefault()->cdn = ['active' => 'N', 'url' => 'https://static.kupshop.local'];
}
/**
* @dataProvider urls_dataProvider
*/
public function testCreateScriptURLInLanguage($page, $language, $expected)
{
$this->languageContext->activate($language);
$url = createScriptURL([
'URL' => 'launch.php',
's' => $page,
'ESCAPE' => 'NO',
]);
$this->assertEquals($expected, $url);
}
public function urls_dataProvider()
{
return [
['producers', 'cs', '/vyrobci/'],
['producers', 'sk', '/vyrobcovia/'],
['favourite', 'cs', '/oblibene/'],
['favourite', 'sk', '/oblubene/'],
];
}
/**
* @dataProvider data_testUrlFinderMedia
*/
public function testUrlFinderMedia($cdn, $file, $expected, $expectedAbsolute)
{
\Settings::getDefault()->cdn['active'] = $cdn;
$this->assertEquals($expected, $this->urlFinder->staticUrl($file));
$this->assertEquals($expectedAbsolute, $this->urlFinder->staticUrlAbsolute($file));
}
public function data_testUrlFinderMedia()
{
return [
['N', '', '/', 'https://www.kupshop.local/'],
['N', '/', '/', 'https://www.kupshop.local/'],
['N', '/test/', '/test/', 'https://www.kupshop.local/test/'],
['N', '/pokus.html', '/pokus.html', 'https://www.kupshop.local/pokus.html'],
['Y', '', 'https://static.kupshop.local/', 'https://static.kupshop.local/'],
['Y', '/', 'https://static.kupshop.local/', 'https://static.kupshop.local/'],
['Y', '/test/', 'https://static.kupshop.local/test/', 'https://static.kupshop.local/test/'],
['Y', '/pokus.html', 'https://static.kupshop.local/pokus.html', 'https://static.kupshop.local/pokus.html'],
];
}
/**
* @dataProvider data_testUrlFinder
*/
public function testUrlFinder($file, $expected, $expectedAbsolute)
{
$this->assertEquals($expected, $this->urlFinder->shopUrl($file));
$this->assertEquals($expectedAbsolute, $this->urlFinder->shopUrlAbsolute($file));
$this->assertEquals($expected, createScriptURL([
'URL' => $file,
]));
$this->assertEquals($expectedAbsolute, createScriptURL([
'URL' => $file,
'absolute' => true,
]));
}
public function data_testUrlFinder()
{
return [
['', '/', 'https://www.kupshop.local/'],
['/', '/', 'https://www.kupshop.local/'],
];
}
}