recreate project

This commit is contained in:
root
2026-02-10 22:11:06 -05:00
commit 663c0cdbda
10149 changed files with 1379710 additions and 0 deletions
@@ -0,0 +1,82 @@
<?php
namespace Tests\App\Controllers\View {
use App\Controllers\View\RegisterController;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\Test\CIUnitTestCase;
use Config\Services;
class TestableRegisterController extends RegisterController
{
public function __construct()
{
// Skip the heavy constructor that connects to the real database.
}
}
class RegisterControllerTest extends CIUnitTestCase
{
private TestableRegisterController $controller;
protected function setUp(): void
{
parent::setUp();
Services::resetSingle('session');
session()->start();
$this->controller = new TestableRegisterController();
}
protected function tearDown(): void
{
session()->remove('captcha_answer');
session()->remove('user_email');
parent::tearDown();
}
public function testIndexGeneratesCaptchaWhenMissing()
{
session()->remove('captcha_answer');
$response = $this->controller->index();
$this->assertIsString($response);
$captcha = session()->get('captcha_answer');
$this->assertNotEmpty($captcha);
$this->assertGreaterThanOrEqual(4, strlen($captcha));
$this->assertLessThanOrEqual(8, strlen($captcha));
}
public function testIndexReusesExistingCaptcha()
{
session()->set('captcha_answer', 'EXISTING');
$response = $this->controller->index();
$this->assertIsString($response);
$this->assertSame('EXISTING', session()->get('captcha_answer'));
}
public function testSuccessRedirectsWhenEmailMissing()
{
session()->remove('user_email');
$response = $this->controller->success();
$this->assertInstanceOf(RedirectResponse::class, $response);
$this->assertStringContainsString('/register', $response->getHeaderLine('Location') ?: '');
}
public function testSuccessReturnsViewWhenEmailPresent()
{
session()->set('user_email', 'parent@example.com');
$response = $this->controller->success();
$this->assertIsString($response);
$this->assertSame('parent@example.com', session()->get('user_email'));
}
}
}