|
|
@@ -0,0 +1,65 @@
|
|
|
+<?php
|
|
|
+// Test language switching logic without redirects
|
|
|
+session_start();
|
|
|
+require_once 'includes/config.php';
|
|
|
+
|
|
|
+echo "=== Testing Language Switching Logic ===\n\n";
|
|
|
+
|
|
|
+// Test URL parsing logic directly
|
|
|
+function testUrlParsing($testUrl) {
|
|
|
+ echo "Testing URL: $testUrl\n";
|
|
|
+
|
|
|
+ $parsedUrl = parse_url($testUrl);
|
|
|
+ $redirectUrl = $parsedUrl['path'];
|
|
|
+
|
|
|
+ if (isset($parsedUrl['query'])) {
|
|
|
+ parse_str($parsedUrl['query'], $queryParams);
|
|
|
+ unset($queryParams['lang']); // Remove lang parameter
|
|
|
+
|
|
|
+ if (!empty($queryParams)) {
|
|
|
+ $redirectUrl .= '?' . http_build_query($queryParams);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ echo "Parsed redirect URL: $redirectUrl\n\n";
|
|
|
+ return $redirectUrl;
|
|
|
+}
|
|
|
+
|
|
|
+// Test various URL scenarios
|
|
|
+$testUrls = [
|
|
|
+ '/index.php?lang=fi&category=test',
|
|
|
+ '/index.php?category=test&lang=fi',
|
|
|
+ '/index.php?lang=fi',
|
|
|
+ '/index.php?category=test&page=2',
|
|
|
+ '/index.php'
|
|
|
+];
|
|
|
+
|
|
|
+foreach ($testUrls as $url) {
|
|
|
+ testUrlParsing($url);
|
|
|
+}
|
|
|
+
|
|
|
+// Test session handling
|
|
|
+echo "=== Testing Session Handling ===\n";
|
|
|
+
|
|
|
+// Simulate language setting
|
|
|
+$_SESSION['language'] = 'fi';
|
|
|
+echo "Session language set to: " . $_SESSION['language'] . "\n";
|
|
|
+
|
|
|
+// Test translation initialization
|
|
|
+try {
|
|
|
+ require_once 'includes/translation.php';
|
|
|
+
|
|
|
+ // Clear GET to avoid redirect
|
|
|
+ $_GET = array();
|
|
|
+
|
|
|
+ $translation = Translation::getInstance();
|
|
|
+ echo "Translation instance created successfully\n";
|
|
|
+ echo "Current language: " . $translation->getCurrentLanguage() . "\n";
|
|
|
+ echo "Supported languages: " . implode(', ', array_keys($translation->getSupportedLanguages())) . "\n";
|
|
|
+
|
|
|
+} catch (Exception $e) {
|
|
|
+ echo "Error: " . $e->getMessage() . "\n";
|
|
|
+}
|
|
|
+
|
|
|
+echo "\n=== Language Switching Logic Test Complete ===\n";
|
|
|
+?>
|