Fix LESS import error and refactor project structure
This commit is contained in:
93
tests/DatabaseTest.php
Normal file
93
tests/DatabaseTest.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
echo "Проверка файлов базы данных:\n";
|
||||
|
||||
$dbConfigPath = __DIR__ . '/../config/database.php';
|
||||
$test->assert(file_exists($dbConfigPath), "Файл config/database.php существует");
|
||||
|
||||
$dbConfigContent = file_get_contents($dbConfigPath);
|
||||
|
||||
$test->assertContains(
|
||||
"pgsql",
|
||||
$dbConfigContent,
|
||||
"Используется драйвер PostgreSQL"
|
||||
);
|
||||
|
||||
$dbCorePath = __DIR__ . '/../app/Core/Database.php';
|
||||
$test->assert(file_exists($dbCorePath), "Файл app/Core/Database.php существует");
|
||||
|
||||
$dbCoreContent = file_get_contents($dbCorePath);
|
||||
|
||||
$test->assertContains(
|
||||
"class Database",
|
||||
$dbCoreContent,
|
||||
"Класс Database определён"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
"getInstance",
|
||||
$dbCoreContent,
|
||||
"Метод getInstance существует"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
"getConnection",
|
||||
$dbCoreContent,
|
||||
"Метод getConnection существует"
|
||||
);
|
||||
|
||||
echo "\nПроверка модели User:\n";
|
||||
|
||||
$userModelPath = __DIR__ . '/../app/Models/User.php';
|
||||
$test->assert(file_exists($userModelPath), "Файл модели User существует");
|
||||
|
||||
$userModelContent = file_get_contents($userModelPath);
|
||||
|
||||
$test->assertContains(
|
||||
"extends Model",
|
||||
$userModelContent,
|
||||
"User наследует Model"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
"protected string \$table = 'users'",
|
||||
$userModelContent,
|
||||
"User использует таблицу 'users'"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
"protected string \$primaryKey = 'user_id'",
|
||||
$userModelContent,
|
||||
"User использует первичный ключ 'user_id'"
|
||||
);
|
||||
|
||||
echo "\nПроверка базовой модели:\n";
|
||||
|
||||
$modelPath = __DIR__ . '/../app/Core/Model.php';
|
||||
$test->assert(file_exists($modelPath), "Файл Core/Model.php существует");
|
||||
|
||||
$modelContent = file_get_contents($modelPath);
|
||||
|
||||
$test->assertContains(
|
||||
"public function create(array \$data)",
|
||||
$modelContent,
|
||||
"Метод create существует"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
"public function update(int \$id, array \$data)",
|
||||
$modelContent,
|
||||
"Метод update существует"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
"public function delete(int \$id)",
|
||||
$modelContent,
|
||||
"Метод delete существует"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
"public function find(int \$id)",
|
||||
$modelContent,
|
||||
"Метод find существует"
|
||||
);
|
||||
77
tests/RegistrationFormTest.php
Normal file
77
tests/RegistrationFormTest.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
echo "Проверка расположения надписи на странице регистрации:\n";
|
||||
|
||||
$profilePath = __DIR__ . '/../профиль.php';
|
||||
$test->assert(file_exists($profilePath), "Файл профиль.php существует");
|
||||
|
||||
$profileContent = file_get_contents($profilePath);
|
||||
|
||||
$hasNoticeInFormBlock = preg_match('/profile-form-block[^}]*form-notice[^}]*РЕГИСТРАЦИЯ/s', $profileContent) === 1;
|
||||
$test->assert($hasNoticeInFormBlock, "Надпись находится внутри profile-form-block (профиль.php)");
|
||||
|
||||
$noticeBeforeTitle = preg_match('/info-circle.*Для доступа.*РЕГИСТРАЦИЯ/s', $profileContent) === 1;
|
||||
$test->assert($noticeBeforeTitle, "Надпись находится перед заголовком РЕГИСТРАЦИЯ (профиль.php)");
|
||||
|
||||
echo "\nПроверка app/Views/auth/register.php:\n";
|
||||
|
||||
$registerViewPath = __DIR__ . '/../app/Views/auth/register.php';
|
||||
$test->assert(file_exists($registerViewPath), "Файл register.php view существует");
|
||||
|
||||
$registerViewContent = file_get_contents($registerViewPath);
|
||||
|
||||
$hasNoticeInFormBlockView = preg_match('/profile-form-block[^}]*info-circle.*Для доступа[^}]*РЕГИСТРАЦИЯ/s', $registerViewContent) === 1;
|
||||
$test->assert($hasNoticeInFormBlockView, "Надпись находится внутри profile-form-block (register.php view)");
|
||||
|
||||
$noticeOutsideContainer = preg_match('/<main[^>]*>.*Для доступа к каталогу.*profile-container/s', $registerViewContent) === 1;
|
||||
$test->assert(!$noticeOutsideContainer, "Надпись 'Для доступа' НЕ находится перед profile-container (register.php view)");
|
||||
|
||||
echo "\nПроверка формы регистрации:\n";
|
||||
|
||||
$test->assertContains(
|
||||
'name="fio"',
|
||||
$profileContent,
|
||||
"Поле ФИО присутствует в форме"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
'name="email"',
|
||||
$profileContent,
|
||||
"Поле email присутствует в форме"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
'name="password"',
|
||||
$profileContent,
|
||||
"Поле password присутствует в форме"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
'name="confirm-password"',
|
||||
$profileContent,
|
||||
"Поле confirm-password присутствует в форме"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
'name="city"',
|
||||
$profileContent,
|
||||
"Поле city присутствует в форме"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
'name="phone"',
|
||||
$profileContent,
|
||||
"Поле phone присутствует в форме"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
'name="privacy"',
|
||||
$profileContent,
|
||||
"Чекбокс согласия присутствует в форме"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
'action="register_handler.php"',
|
||||
$profileContent,
|
||||
"Форма отправляется на register_handler.php"
|
||||
);
|
||||
82
tests/SessionTest.php
Normal file
82
tests/SessionTest.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
echo "Проверка работы сессий на страницах:\n";
|
||||
|
||||
$pagesWithSession = [
|
||||
'Доставка.php',
|
||||
'Гарантия.php',
|
||||
'услуги.php',
|
||||
'cite_mebel.php',
|
||||
'catalog.php',
|
||||
'профиль.php',
|
||||
];
|
||||
|
||||
foreach ($pagesWithSession as $page) {
|
||||
$pagePath = __DIR__ . '/../' . $page;
|
||||
|
||||
if (file_exists($pagePath)) {
|
||||
$content = file_get_contents($pagePath);
|
||||
|
||||
$hasSessionStart = str_contains($content, 'session_start()');
|
||||
$test->assert($hasSessionStart, "$page содержит session_start()");
|
||||
|
||||
} else {
|
||||
$test->assert(false, "$page - файл не найден");
|
||||
}
|
||||
}
|
||||
|
||||
echo "\nПроверка header_common.php:\n";
|
||||
|
||||
$headerCommonPath = __DIR__ . '/../header_common.php';
|
||||
$test->assert(file_exists($headerCommonPath), "Файл header_common.php существует");
|
||||
|
||||
$headerContent = file_get_contents($headerCommonPath);
|
||||
|
||||
$test->assertContains(
|
||||
"session_status() == PHP_SESSION_NONE",
|
||||
$headerContent,
|
||||
"header_common.php проверяет статус сессии перед стартом"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
"\$isAdmin",
|
||||
$headerContent,
|
||||
"header_common.php использует переменную isAdmin"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
"Админ",
|
||||
$headerContent,
|
||||
"header_common.php отображает статус 'Админ'"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
"Пользователь",
|
||||
$headerContent,
|
||||
"header_common.php отображает статус 'Пользователь'"
|
||||
);
|
||||
|
||||
echo "\nПроверка login_handler.php:\n";
|
||||
|
||||
$loginHandlerPath = __DIR__ . '/../login_handler.php';
|
||||
$test->assert(file_exists($loginHandlerPath), "Файл login_handler.php существует");
|
||||
|
||||
$loginHandlerContent = file_get_contents($loginHandlerPath);
|
||||
|
||||
$test->assertContains(
|
||||
"\$_SESSION['isAdmin']",
|
||||
$loginHandlerContent,
|
||||
"login_handler.php сохраняет isAdmin в сессию"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
"\$_SESSION['isLoggedIn']",
|
||||
$loginHandlerContent,
|
||||
"login_handler.php сохраняет isLoggedIn в сессию"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
"password_verify",
|
||||
$loginHandlerContent,
|
||||
"login_handler.php использует password_verify для проверки пароля"
|
||||
);
|
||||
80
tests/TestRunner.php
Normal file
80
tests/TestRunner.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', '1');
|
||||
|
||||
define('COLOR_GREEN', "\033[32m");
|
||||
define('COLOR_RED', "\033[31m");
|
||||
define('COLOR_YELLOW', "\033[33m");
|
||||
define('COLOR_RESET', "\033[0m");
|
||||
|
||||
class TestRunner
|
||||
{
|
||||
private int $passed = 0;
|
||||
private int $failed = 0;
|
||||
private array $errors = [];
|
||||
|
||||
public function assert(bool $condition, string $message): void
|
||||
{
|
||||
if ($condition) {
|
||||
$this->passed++;
|
||||
echo COLOR_GREEN . "✓ " . COLOR_RESET . $message . "\n";
|
||||
} else {
|
||||
$this->failed++;
|
||||
$this->errors[] = $message;
|
||||
echo COLOR_RED . "✗ " . COLOR_RESET . $message . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
public function assertEquals($expected, $actual, string $message): void
|
||||
{
|
||||
$this->assert($expected === $actual, $message . " (expected: " . var_export($expected, true) . ", got: " . var_export($actual, true) . ")");
|
||||
}
|
||||
|
||||
public function assertNotNull($value, string $message): void
|
||||
{
|
||||
$this->assert($value !== null, $message);
|
||||
}
|
||||
|
||||
public function assertNull($value, string $message): void
|
||||
{
|
||||
$this->assert($value === null, $message);
|
||||
}
|
||||
|
||||
public function assertContains(string $needle, string $haystack, string $message): void
|
||||
{
|
||||
$this->assert(str_contains($haystack, $needle), $message);
|
||||
}
|
||||
|
||||
public function summary(): void
|
||||
{
|
||||
echo "\n" . str_repeat("=", 50) . "\n";
|
||||
echo COLOR_GREEN . "Пройдено: {$this->passed}" . COLOR_RESET . "\n";
|
||||
echo COLOR_RED . "Провалено: {$this->failed}" . COLOR_RESET . "\n";
|
||||
|
||||
if (!empty($this->errors)) {
|
||||
echo COLOR_YELLOW . "\nОшибки:\n" . COLOR_RESET;
|
||||
foreach ($this->errors as $error) {
|
||||
echo " - {$error}\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo str_repeat("=", 50) . "\n";
|
||||
|
||||
exit($this->failed > 0 ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../config/database.php';
|
||||
|
||||
$test = new TestRunner();
|
||||
|
||||
echo "\n" . COLOR_YELLOW . "=== ТЕСТЫ ПРОЕКТА AETERNA ===" . COLOR_RESET . "\n\n";
|
||||
|
||||
$testFiles = glob(__DIR__ . '/*Test.php');
|
||||
foreach ($testFiles as $testFile) {
|
||||
echo COLOR_YELLOW . "\n--- " . basename($testFile) . " ---" . COLOR_RESET . "\n";
|
||||
require_once $testFile;
|
||||
}
|
||||
|
||||
$test->summary();
|
||||
70
tests/UserRegistrationTest.php
Normal file
70
tests/UserRegistrationTest.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
echo "Проверка модели User:\n";
|
||||
|
||||
$userModelPath = __DIR__ . '/../app/Models/User.php';
|
||||
$test->assert(file_exists($userModelPath), "Файл модели User существует");
|
||||
|
||||
$userModelContent = file_get_contents($userModelPath);
|
||||
|
||||
$test->assertContains(
|
||||
"'is_admin' => \$isAdmin ? 'true' : 'false'",
|
||||
$userModelContent,
|
||||
"is_admin преобразуется в строку для PostgreSQL"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
"'is_active' => 'true'",
|
||||
$userModelContent,
|
||||
"is_active преобразуется в строку для PostgreSQL"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
"public function register(array \$data)",
|
||||
$userModelContent,
|
||||
"Метод register существует в модели User"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
"public function authenticate(string \$email, string \$password)",
|
||||
$userModelContent,
|
||||
"Метод authenticate существует в модели User"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
"public function hashPassword(string \$password)",
|
||||
$userModelContent,
|
||||
"Метод hashPassword существует в модели User"
|
||||
);
|
||||
|
||||
echo "\nПроверка register_handler.php:\n";
|
||||
|
||||
$registerHandlerPath = __DIR__ . '/../register_handler.php';
|
||||
$test->assert(file_exists($registerHandlerPath), "Файл register_handler.php существует");
|
||||
|
||||
$registerHandlerContent = file_get_contents($registerHandlerPath);
|
||||
|
||||
$test->assertContains(
|
||||
"filter_var(\$email, FILTER_VALIDATE_EMAIL)",
|
||||
$registerHandlerContent,
|
||||
"Валидация email присутствует"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
"strlen(\$password) < 6",
|
||||
$registerHandlerContent,
|
||||
"Проверка минимальной длины пароля присутствует"
|
||||
);
|
||||
|
||||
$test->assertContains(
|
||||
"\$password !== \$confirm_password",
|
||||
$registerHandlerContent,
|
||||
"Проверка совпадения паролей присутствует"
|
||||
);
|
||||
|
||||
$hasBooleanConversion = str_contains($registerHandlerContent, "\$is_admin ? 'true' : 'false'")
|
||||
|| str_contains($registerHandlerContent, "\$is_admin ? 1 : 0");
|
||||
$test->assert(
|
||||
$hasBooleanConversion,
|
||||
"is_admin преобразуется для PostgreSQL в register_handler"
|
||||
);
|
||||
Reference in New Issue
Block a user