TransWar File Browser

Path: C:\

<?php

/**
 * Script de Validação e Testes Automatizados - Exportador Excel modelo.xlsx
 */

require_once __DIR__ . '/includes/functions.php';

echo "=========================================================\n";
echo "  TESTES EXPORTADOR EXCEL MODELO.XLSX: ARMAZENAGEM       \n";
echo "=========================================================\n\n";

$passedCount = 0;
$failedCount = 0;

function assertTest(string $name, bool $condition, string $msg = '') {
    global $passedCount, $failedCount;
    if ($condition) {
        echo "  [OK] {$name}\n";
        $passedCount++;
    } else {
        echo "  [FALHA] {$name}: {$msg}\n";
        $failedCount++;
    }
}

// 1. Teste da Presença do Arquivo modelo.xlsx
$templatePath = __DIR__ . '/modelo.xlsx';
assertTest("Presença do arquivo modelo.xlsx na raiz do projeto", file_exists($templatePath));

// 2. Teste de Simulação da Geração do Excel no ZipArchive Fallback
$tempCopy = __DIR__ . '/data/test_export_modelo.xlsx';
copy($templatePath, $tempCopy);

$zip = new ZipArchive();
$openOk = $zip->open($tempCopy);
assertTest("Abertura do arquivo modelo.xlsx via ZipArchive", $openOk === true);

if ($openOk === true) {
    $sheetXml = $zip->getFromName('xl/worksheets/sheet1.xml');
    assertTest("Leitura do layout de planilhas xl/worksheets/sheet1.xml", !empty($sheetXml));

    $dom = new DOMDocument();
    $dom->loadXML($sheetXml);
    $xpath = new DOMXPath($dom);
    $xpath->registerNamespace('s', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main');

    // Testar presença da célula C2 (data inicial)
    $c2Nodes = $xpath->query('//s:c[@r="C2"]');
    assertTest("Identificação da célula C2 para a Data Inicial do Mês", $c2Nodes->length > 0);

    // Testar presença da célula F6 com fórmula existente =C6+D6-E6
    $f6Nodes = $xpath->query('//s:c[@r="F6"]/s:f');
    assertTest("Preservação da Fórmula da Coluna F (=C6+D6-E6)", $f6Nodes->length > 0 && strpos($f6Nodes->item(0)->nodeValue, 'C6') !== false);

    $zip->close();
    @unlink($tempCopy);
}

echo "\n---------------------------------------------------------\n";
echo "  RESULTADO DOS TESTES: {$passedCount} Passaram | {$failedCount} Falharam\n";
echo "---------------------------------------------------------\n\n";

if ($failedCount === 0) {
    echo ">>> TODOS OS TESTES DO EXPORTADOR EXCEL PASSARAM COM SUCESSO! <<<\n";
} else {
    echo ">>> ALGUNS TESTES FALHARAM. VERIFIQUE ACIMA. <<<\n";
}