uploadDir = dirname(__FILE__) . '/temp/'; } public function runTests() { echo "

Test Configurație eFactura

"; // Testează config.json $this->testConfigFile(); // Testează directorul temp $this->testTempDirectory(); // Testează permisiuni $this->testPermissions(); // Testează request cu XML $this->testXMLUpload(); // Afișează rezultate $this->displayResults(); } private function testConfigFile() { echo "

1. Verificare config.json

"; try { // Verifică dacă există config.json if (!file_exists('config.json')) { throw new Exception("config.json nu există!"); } // Încearcă să citească config.json $this->config = json_decode(file_get_contents('config.json'), true); if (!$this->config) { throw new Exception("config.json nu este un JSON valid!"); } // Verifică structura $required = ['api_key', 'allowed_ips', 'temp_file_lifetime']; foreach ($required as $field) { if (!isset($this->config[$field])) { throw new Exception("Lipsește câmpul: $field"); } } $this->addResult('config', true, "config.json este valid și complet"); } catch (Exception $e) { $this->addResult('config', false, $e->getMessage()); } } private function testTempDirectory() { echo "

2. Verificare Director Temp

"; try { if (!file_exists($this->uploadDir)) { mkdir($this->uploadDir, 0777, true); $this->addResult('temp_create', true, "Directorul temp a fost creat"); } if (!is_writable($this->uploadDir)) { throw new Exception("Directorul temp nu are permisiuni de scriere!"); } $testFile = $this->uploadDir . 'test.txt'; if (file_put_contents($testFile, 'test')) { unlink($testFile); $this->addResult('temp_write', true, "Test scriere în temp reușit"); } else { throw new Exception("Nu se poate scrie în directorul temp!"); } } catch (Exception $e) { $this->addResult('temp_write', false, $e->getMessage()); } } private function testPermissions() { echo "

3. Verificare Permisiuni

"; // Verifică permisiuni config.json $configPerms = fileperms('config.json'); $this->addResult( 'config_perms', ($configPerms & 0x0092), "Permisiuni config.json: " . substr(sprintf('%o', $configPerms), -4) ); // Verifică permisiuni temp $tempPerms = fileperms($this->uploadDir); $this->addResult( 'temp_perms', ($tempPerms & 0x0777), "Permisiuni temp/: " . substr(sprintf('%o', $tempPerms), -4) ); } private function testXMLUpload() { echo "

4. Test Upload XML

"; // Creează un XML de test $testXML = 'Test XML'; // Simulează un request către receiver.php $ch = curl_init('http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/receiver.php'); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => $testXML, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => [ 'Content-Type: application/xml', 'X-Api-Key: ' . $this->config['api_key'] ] ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode === 200) { $result = json_decode($response, true); if ($result && $result['success']) { $this->addResult('xml_upload', true, "Upload XML reușit"); // Încearcă să șteargă fișierul if (isset($result['fileName'])) { @unlink($this->uploadDir . $result['fileName']); } } else { $this->addResult('xml_upload', false, "Răspuns invalid la upload"); } } else { $this->addResult('xml_upload', false, "Upload eșuat cu codul: $httpCode"); } } private function addResult($test, $success, $message) { $this->results[$test] = [ 'success' => $success, 'message' => $message ]; $status = $success ? '✅' : '❌'; echo "
"; echo "$status $message"; echo "
"; } private function displayResults() { echo "

Rezultate Finale

"; $allSuccess = true; foreach ($this->results as $test => $result) { if (!$result['success']) { $allSuccess = false; break; } } if ($allSuccess) { echo "
"; echo "✅ Toate testele au trecut cu succes!"; echo "
"; } else { echo "
"; echo "❌ Unele teste au eșuat. Verificați mesajele de mai sus."; echo "
"; } } } // Stilizare pagină ?> Test Configurație eFactura runTests(); ?>