fix: test
This commit is contained in:
@@ -16,6 +16,14 @@ class AppMetaInitializer {
|
|||||||
this.setMeta('theme-color', '#000000');
|
this.setMeta('theme-color', '#000000');
|
||||||
this.setMeta('msapplication-navbutton-color', '#000000');
|
this.setMeta('msapplication-navbutton-color', '#000000');
|
||||||
this.setMeta('apple-mobile-web-app-status-bar-style', 'black-translucent');
|
this.setMeta('apple-mobile-web-app-status-bar-style', 'black-translucent');
|
||||||
|
|
||||||
|
// Добавляем apple-touch-icon теги
|
||||||
|
if (this.settings.apple_touch_icon) {
|
||||||
|
this.addLink('apple-touch-icon', this.settings.apple_touch_icon);
|
||||||
|
} else {
|
||||||
|
// Добавляем дефолтный apple-touch-icon, если не указан
|
||||||
|
this.addLink('apple-touch-icon', '/favicon.ico');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private setMeta(name: string, content: string) {
|
private setMeta(name: string, content: string) {
|
||||||
|
|||||||
@@ -60,11 +60,11 @@ class ImageFactoryTest extends TestCase
|
|||||||
|
|
||||||
$factory = new ImageFactory($this->imageDir, $this->siteUrl, 'gd');
|
$factory = new ImageFactory($this->imageDir, $this->siteUrl, 'gd');
|
||||||
|
|
||||||
// Ожидание: http://localhost/image/cache/catalog/test_...
|
// Ожидание: http://localhost/image/cache/telecart/catalog/test_...
|
||||||
$url = $factory->make('catalog/test.png')->url();
|
$url = $factory->make('catalog/test.png')->url();
|
||||||
|
|
||||||
// Проверяем, что 'cache' не пострадал от ltrim
|
// Проверяем, что 'cache' не пострадал от ltrim и путь содержит telecart
|
||||||
$this->assertStringContainsString('/image/cache/catalog/test', $url, 'URL corrupted: ' . $url);
|
$this->assertStringContainsString('/image/cache/telecart/catalog/test', $url, 'URL corrupted: ' . $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFilenameLengthAndDuplication()
|
public function testFilenameLengthAndDuplication()
|
||||||
@@ -84,7 +84,7 @@ class ImageFactoryTest extends TestCase
|
|||||||
$expectedHash = substr(hash('SHA256', json_encode(['resize' => ['width' => 100, 'height' => 100]])), 0, 12);
|
$expectedHash = substr(hash('SHA256', json_encode(['resize' => ['width' => 100, 'height' => 100]])), 0, 12);
|
||||||
$this->assertStringContainsString($expectedHash, $filename);
|
$this->assertStringContainsString($expectedHash, $filename);
|
||||||
|
|
||||||
$this->assertFileExists($this->imageDir . '/cache/test_' . $expectedHash . '.webp');
|
$this->assertFileExists($this->imageDir . '/cache/telecart/test_' . $expectedHash . '.webp');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMissingImageFallback()
|
public function testMissingImageFallback()
|
||||||
@@ -100,7 +100,7 @@ class ImageFactoryTest extends TestCase
|
|||||||
$this->assertStringContainsString('no_image', $url);
|
$this->assertStringContainsString('no_image', $url);
|
||||||
|
|
||||||
// Проверяем, что сам файл создался (конвертация в webp)
|
// Проверяем, что сам файл создался (конвертация в webp)
|
||||||
$this->assertFileExists($this->imageDir . '/cache/no_image.webp');
|
$this->assertFileExists($this->imageDir . '/cache/telecart/no_image.webp');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMissingFallbackImageSafeFail()
|
public function testMissingFallbackImageSafeFail()
|
||||||
|
|||||||
@@ -3,9 +3,111 @@
|
|||||||
namespace Tests\Unit\Framework;
|
namespace Tests\Unit\Framework;
|
||||||
|
|
||||||
use Openguru\OpenCartFramework\Http\Request;
|
use Openguru\OpenCartFramework\Http\Request;
|
||||||
use PHPUnit\Framework\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class RequestTest extends TestCase
|
class RequestTest extends TestCase
|
||||||
{
|
{
|
||||||
|
/** @test */
|
||||||
|
public function get_returns_query_parameter(): void
|
||||||
|
{
|
||||||
|
$request = Request::create('/test?key=value', 'GET');
|
||||||
|
|
||||||
|
$this->assertEquals('value', $request->get('key'));
|
||||||
|
$this->assertNull($request->get('non_existent'));
|
||||||
|
$this->assertEquals('default', $request->get('non_existent', 'default'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function json_returns_decoded_json_content(): void
|
||||||
|
{
|
||||||
|
$data = ['key' => 'value', 'nested' => ['foo' => 'bar']];
|
||||||
|
$request = Request::create('/test', 'POST', [], [], [], [], json_encode($data));
|
||||||
|
|
||||||
|
$this->assertEquals($data, $request->json());
|
||||||
|
$this->assertEquals('value', $request->json('key'));
|
||||||
|
$this->assertEquals('bar', $request->json('nested.foo'));
|
||||||
|
$this->assertNull($request->json('non_existent'));
|
||||||
|
$this->assertEquals('default', $request->json('non_existent', 'default'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function json_returns_default_for_empty_content(): void
|
||||||
|
{
|
||||||
|
$request = Request::create('/test', 'POST');
|
||||||
|
|
||||||
|
$this->assertNull($request->json());
|
||||||
|
$this->assertEquals('default', $request->json('key', 'default'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function get_client_ip_returns_forwarded_for(): void
|
||||||
|
{
|
||||||
|
$_SERVER['HTTP_X_FORWARDED_FOR'] = '192.168.1.1';
|
||||||
|
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||||
|
|
||||||
|
$request = Request::create('/test');
|
||||||
|
|
||||||
|
$this->assertEquals('192.168.1.1', $request->getClientIp());
|
||||||
|
|
||||||
|
unset($_SERVER['HTTP_X_FORWARDED_FOR'], $_SERVER['REMOTE_ADDR']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function get_client_ip_returns_remote_addr_when_no_forwarded_for(): void
|
||||||
|
{
|
||||||
|
unset($_SERVER['HTTP_X_FORWARDED_FOR']);
|
||||||
|
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||||
|
|
||||||
|
$request = Request::create('/test');
|
||||||
|
|
||||||
|
$this->assertEquals('127.0.0.1', $request->getClientIp());
|
||||||
|
|
||||||
|
unset($_SERVER['REMOTE_ADDR']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function get_user_agent_returns_user_agent(): void
|
||||||
|
{
|
||||||
|
$_SERVER['HTTP_USER_AGENT'] = 'Test User Agent';
|
||||||
|
|
||||||
|
$request = Request::create('/test');
|
||||||
|
|
||||||
|
$this->assertEquals('Test User Agent', $request->getUserAgent());
|
||||||
|
|
||||||
|
unset($_SERVER['HTTP_USER_AGENT']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function header_returns_header_value(): void
|
||||||
|
{
|
||||||
|
$request = Request::create('/test', 'GET', [], [], [], [
|
||||||
|
'HTTP_X_CUSTOM_HEADER' => 'custom-value'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals('custom-value', $request->header('X-Custom-Header'));
|
||||||
|
$this->assertNull($request->header('Non-Existent'));
|
||||||
|
$this->assertEquals('default', $request->header('Non-Existent', 'default'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function get_api_key_returns_api_key_from_header(): void
|
||||||
|
{
|
||||||
|
$_SERVER['HTTP_X_API_KEY'] = 'test-api-key';
|
||||||
|
|
||||||
|
$request = Request::create('/test');
|
||||||
|
|
||||||
|
$this->assertEquals('test-api-key', $request->getApiKey());
|
||||||
|
|
||||||
|
unset($_SERVER['HTTP_X_API_KEY']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function get_api_key_returns_null_when_not_set(): void
|
||||||
|
{
|
||||||
|
unset($_SERVER['HTTP_X_API_KEY']);
|
||||||
|
|
||||||
|
$request = Request::create('/test');
|
||||||
|
|
||||||
|
$this->assertNull($request->getApiKey());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user