init($container); // Create Session (needed for CSRF tokens) $session = new InMemorySession(); // Create LiveComponentRenderer $liveComponentRenderer = new LiveComponentRenderer($templateRenderer, $session); // Create ComponentRegistry $registry = new ComponentRegistry($liveComponentRenderer); echo "=== SSE Channel Rendering Test ===\n\n"; // Test 1: NotificationCenter Component echo "Test 1: NotificationCenter Component\n"; echo "-------------------------------------\n"; $notificationComponent = new NotificationCenterComponent( id: new ComponentId('notification-center', 'user-123'), initialData: null, notifications: [ [ 'id' => 'notif-1', 'title' => 'Test Notification', 'message' => 'This is a test', 'type' => 'info', 'read' => false, 'timestamp' => time(), ], ], unreadCount: 1, filter: 'all', showPanel: false ); // Get SSE channel $sseChannel = $notificationComponent->getSseChannel(); echo "SSE Channel: {$sseChannel}\n"; // Render with wrapper $html = $registry->renderWithWrapper($notificationComponent); // Check if data-sse-channel is present if (str_contains($html, 'data-sse-channel=')) { echo "✅ SUCCESS: data-sse-channel attribute found\n"; // Extract the channel value if (preg_match('/data-sse-channel="([^"]+)"/', $html, $matches)) { $renderedChannel = $matches[1]; echo " Rendered channel: {$renderedChannel}\n"; if ($renderedChannel === $sseChannel) { echo "✅ Channel matches getSseChannel() return value\n"; } else { echo "❌ FAIL: Channel mismatch! Expected: {$sseChannel}, Got: {$renderedChannel}\n"; } } } else { echo "❌ FAIL: data-sse-channel attribute NOT found\n"; echo "HTML preview:\n"; echo substr($html, 0, 300) . "...\n"; } echo "\n"; // Test 2: LivePresence Component echo "Test 2: LivePresence Component\n"; echo "-------------------------------------\n"; $presenceComponent = new LivePresenceComponent( id: new ComponentId('live-presence', 'room-lobby'), initialData: null, users: [ [ 'user_id' => 'user-1', 'user_name' => 'John Doe', 'avatar_url' => '', 'status' => 'online', 'joined_at' => time() - 300, 'last_seen' => time(), ], ], showAvatars: true, showNames: true, showCount: true, maxVisibleUsers: 10, presenceTimeout: 300, allowAnonymous: false ); // Get SSE channel $sseChannel = $presenceComponent->getSseChannel(); echo "SSE Channel: {$sseChannel}\n"; // Render with wrapper $html = $registry->renderWithWrapper($presenceComponent); // Check if data-sse-channel is present if (str_contains($html, 'data-sse-channel=')) { echo "✅ SUCCESS: data-sse-channel attribute found\n"; // Extract the channel value if (preg_match('/data-sse-channel="([^"]+)"/', $html, $matches)) { $renderedChannel = $matches[1]; echo " Rendered channel: {$renderedChannel}\n"; if ($renderedChannel === $sseChannel) { echo "✅ Channel matches getSseChannel() return value\n"; } else { echo "❌ FAIL: Channel mismatch! Expected: {$sseChannel}, Got: {$renderedChannel}\n"; } } } else { echo "❌ FAIL: data-sse-channel attribute NOT found\n"; echo "HTML preview:\n"; echo substr($html, 0, 300) . "...\n"; } echo "\n"; // Test 3: Verify HTML structure echo "Test 3: Verify Complete HTML Structure\n"; echo "-------------------------------------\n"; $html = $registry->renderWithWrapper($notificationComponent); $requiredAttributes = [ 'data-live-component', 'data-state', 'data-csrf-token', 'data-sse-channel', ]; $allPresent = true; foreach ($requiredAttributes as $attr) { if (str_contains($html, $attr . '=')) { echo "✅ {$attr} present\n"; } else { echo "❌ {$attr} MISSING\n"; $allPresent = false; } } if ($allPresent) { echo "\n✅ ALL TESTS PASSED - SSE Channel Rendering works!\n"; } else { echo "\n❌ SOME TESTS FAILED - Check implementation\n"; } echo "\n=== Test Complete ===\n";