WizdomWeb/tests/ComponentTests.php

60 lines
1.9 KiB
PHP

<?php
/**
* Unit Tests for Wizdom Networks Components
*
* This test suite validates the core components, utilities, and partials developed so far.
* Uses PHPUnit for structured unit testing.
*/
use PHPUnit\Framework\TestCase;
use WizdomNetworks\WizeWeb\Utils\Logger;
use WizdomNetworks\WizeWeb\Utils\Validator;
class ComponentTests extends TestCase
{
/**
* Test Main Layout Rendering with Debugging
*/
public function testMainLayoutRendersCorrectly()
{
ob_start();
// Debugging: Log entry into the test
error_log("[DEBUG] Entering testMainLayoutRendersCorrectly");
// Define required variables to prevent errors
$title = 'Test Page';
$content = '<p>Test Content</p>';
$showHero = false;
$showSlider = null;
// Define a Mock Controller class with a render method
$mockController = new class {
public function render($view, $data = []) {
error_log("[DEBUG] Render called for view: $view");
return "<!-- Mocked Render: $view -->";
}
};
// Execute main.php within a function scope to use the mock controller
$output = (function () use ($mockController, $title, $content, $showHero, $showSlider) {
ob_start();
$this->controller = $mockController; // Assign mock controller for $this reference
include __DIR__ . '/../resources/views/layouts/main.php';
return ob_get_clean();
})();
// Debugging: Log output from the test
error_log("[DEBUG] Test Output: " . substr($output, 0, 500)); // Log first 500 chars
$this->assertStringContainsString('<body>', $output);
$this->assertStringContainsString('<header>', $output);
$this->assertStringContainsString('<footer>', $output);
}
// Other tests remain unchanged...
}
?>