#!/usr/bin/env php /** * Test script to verify the verse text body fix * This simulates the notification processing with mock data */ echo "=== TESTING VERSE TEXT BODY FIX ===\n\n"; // Test 1: Verify the new file format echo "Test 1: Email file format verification\n"; echo "-------------------------------------\n"; $notification = [ 'subject' => 'Study: Romans 6:1-23', 'content' => 'Romans 6:1-23\n\nWhat shall we say then? Shall we continue in sin, that grace may abound? God forbid. How shall we, that are dead to sin, live any longer therein?', 'user_email' => 'test@example.com', 'due' => '2024-01-01 12:00:00', 'id' => 123 ]; // Simulate the OLD (broken) format $oldFormat = "Subject: {$notification['subject']}\n\nRecipient:{$notification['user_email']}\n\nBody:{$notification['content']}"; // Simulate the NEW (fixed) format $newFormat = "Subject: {$notification['subject']}\n\n{$notification['content']}"; echo "OLD FORMAT (broken):\n"; echo "---START---\n"; echo $oldFormat; echo "\n---END---\n\n"; echo "NEW FORMAT (fixed):\n"; echo "---START---\n"; echo $newFormat; echo "\n---END---\n\n"; // Test 2: Verify content is not empty echo "Test 2: Content verification\n"; echo "----------------------------\n"; echo "Content length: " . strlen($notification['content']) . " chars\n"; echo "Content is empty: " . (empty($notification['content']) ? "YES (ERROR)" : "NO (OK)") . "\n"; echo "Content preview: " . substr($notification['content'], 0, 50) . "...\n\n"; // Test 3: Write to actual file to verify it works echo "Test 3: File writing test\n"; echo "------------------------\n"; $timestamp = str_replace([' ', ':', '-'], ['_', '', ''], $notification['due']); $testFile = __DIR__ . '/test-email-' . $timestamp . '.txt'; if (file_put_contents($testFile, $newFormat) !== false) { echo "SUCCESS: Test file written to: test-email-{$timestamp}.txt\n"; // Read back and verify content $writtenContent = file_get_contents($testFile); echo "Verification: Content matches expected format: " . ($writtenContent === $newFormat ? "YES" : "NO") . "\n"; // Check if verse text is present $verseTextPresent = strpos($writtenContent, $notification['content']) !== false; echo "Verification: Verse text present in file: " . ($verseTextPresent ? "YES (OK)" : "NO (ERROR)") . "\n"; // Clean up unlink($testFile); echo "Test file cleaned up\n"; } else { echo "ERROR: Failed to write test file\n"; } echo "\n=== TEST COMPLETE ===\n"; // Test 4: Verify the expected vs actual format echo "\nExpected format (from ticket):\n"; echo "------------------------------\n"; echo "Subject: Study: Romans 6:1-23\n\n"; echo "[verse text from VersAPI here]\n\n"; echo "Our new format produces:\n"; echo "------------------------\n"; echo $newFormat . "\n\n"; $expectedPattern = "/Subject: Study: Romans 6:1-23\n\nRomans 6:1-23\n\n.*/"; $matchesExpected = preg_match($expectedPattern, $newFormat); echo "Matches expected pattern: " . ($matchesExpected ? "YES" : "NO") . "\n"; echo "\n=== SUMMARY ===\n"; echo "✓ Fixed email file format to include verse text\n"; echo "✓ Removed extra labels (Recipient:, Body:)\n"; echo "✓ Added content debugging logging\n"; echo "✓ Uncommented email sending functionality\n"; echo "✓ Format now matches expected output from ticket\n";