v7.0.0-beta.1 release
This commit is contained in:
commit
6595fd0eb5
3967 files changed
+1875383
No files matched your search
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Installer;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* deleteDirectory() 함수의 보호 파일 보존 테스트
|
||||
*
|
||||
* .gitkeep, .gitignore 등 Git 추적 파일이 삭제되지 않는지 검증합니다.
|
||||
*/
|
||||
class DeleteDirectoryTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* 테스트용 임시 디렉토리 경로
|
||||
*/
|
||||
private string $tempDir;
|
||||
|
||||
/**
|
||||
* 테스트 전 인스톨러 함수 로드 및 임시 디렉토리 생성
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
// 상수 정의 (한 번만)
|
||||
if (! defined('BASE_PATH')) {
|
||||
define('BASE_PATH', dirname(__DIR__, 2).'/..');
|
||||
}
|
||||
if (! defined('REQUIRED_DIRECTORY_PERMISSIONS')) {
|
||||
define('REQUIRED_DIRECTORY_PERMISSIONS', 0770);
|
||||
}
|
||||
if (! defined('REQUIRED_DIRECTORY_PERMISSIONS_DISPLAY')) {
|
||||
define('REQUIRED_DIRECTORY_PERMISSIONS_DISPLAY', '770');
|
||||
}
|
||||
if (! defined('REQUIRED_DIRECTORIES')) {
|
||||
define('REQUIRED_DIRECTORIES', ['storage' => true]);
|
||||
}
|
||||
if (! defined('SUPPORTED_LANGUAGES')) {
|
||||
define('SUPPORTED_LANGUAGES', ['ko' => '한국어', 'en' => 'English']);
|
||||
}
|
||||
if (! defined('INSTALLER_BASE_URL')) {
|
||||
define('INSTALLER_BASE_URL', '/install');
|
||||
}
|
||||
|
||||
// 인스톨러 함수 로드
|
||||
require_once base_path('public/install/includes/functions.php');
|
||||
require_once base_path('public/install/api/rollback-functions.php');
|
||||
|
||||
// 임시 디렉토리 생성
|
||||
$this->tempDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'g7_test_delete_' . uniqid();
|
||||
mkdir($this->tempDir, 0755, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 테스트 후 임시 디렉토리 정리
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->cleanupTempDir($this->tempDir);
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* deleteDirectory()가 .gitkeep 파일을 보존하는지 확인합니다.
|
||||
*/
|
||||
public function test_preserves_gitkeep_file(): void
|
||||
{
|
||||
// Given: 디렉토리에 .gitkeep과 일반 파일이 있음
|
||||
file_put_contents($this->tempDir . '/.gitkeep', '');
|
||||
file_put_contents($this->tempDir . '/some_file.txt', 'test');
|
||||
mkdir($this->tempDir . '/subdir', 0755);
|
||||
file_put_contents($this->tempDir . '/subdir/nested.txt', 'test');
|
||||
|
||||
// When: deleteDirectory 호출 (기본: removeDir=false)
|
||||
$result = deleteDirectory($this->tempDir);
|
||||
|
||||
// Then: .gitkeep은 보존, 나머지는 삭제, 디렉토리 자체는 유지
|
||||
$this->assertTrue($result);
|
||||
$this->assertDirectoryExists($this->tempDir);
|
||||
$this->assertFileExists($this->tempDir . '/.gitkeep');
|
||||
$this->assertFileDoesNotExist($this->tempDir . '/some_file.txt');
|
||||
$this->assertDirectoryDoesNotExist($this->tempDir . '/subdir');
|
||||
}
|
||||
|
||||
/**
|
||||
* deleteDirectory()가 .gitignore 파일을 보존하는지 확인합니다.
|
||||
*/
|
||||
public function test_preserves_gitignore_file(): void
|
||||
{
|
||||
// Given: 디렉토리에 .gitignore와 일반 파일이 있음
|
||||
file_put_contents($this->tempDir . '/.gitignore', '*');
|
||||
file_put_contents($this->tempDir . '/data.log', 'log');
|
||||
|
||||
// When
|
||||
$result = deleteDirectory($this->tempDir);
|
||||
|
||||
// Then
|
||||
$this->assertTrue($result);
|
||||
$this->assertDirectoryExists($this->tempDir);
|
||||
$this->assertFileExists($this->tempDir . '/.gitignore');
|
||||
$this->assertFileDoesNotExist($this->tempDir . '/data.log');
|
||||
}
|
||||
|
||||
/**
|
||||
* deleteDirectory()가 보호 파일이 없으면 디렉토리를 유지하되 비워두는지 확인합니다.
|
||||
*/
|
||||
public function test_keeps_directory_when_no_preserve_files_and_remove_dir_false(): void
|
||||
{
|
||||
// Given: 보호 파일 없이 일반 파일만 있음
|
||||
file_put_contents($this->tempDir . '/file1.txt', 'test');
|
||||
file_put_contents($this->tempDir . '/file2.txt', 'test');
|
||||
|
||||
// When: removeDir=false (기본값)
|
||||
$result = deleteDirectory($this->tempDir);
|
||||
|
||||
// Then: 디렉토리 자체는 유지, 내용물은 삭제
|
||||
$this->assertTrue($result);
|
||||
$this->assertDirectoryExists($this->tempDir);
|
||||
$this->assertFileDoesNotExist($this->tempDir . '/file1.txt');
|
||||
$this->assertFileDoesNotExist($this->tempDir . '/file2.txt');
|
||||
}
|
||||
|
||||
/**
|
||||
* deleteDirectory()가 removeDir=true이고 보호 파일이 있으면 디렉토리를 유지하는지 확인합니다.
|
||||
*/
|
||||
public function test_keeps_directory_when_preserve_files_exist_even_with_remove_dir(): void
|
||||
{
|
||||
// Given: .gitkeep이 있음
|
||||
file_put_contents($this->tempDir . '/.gitkeep', '');
|
||||
file_put_contents($this->tempDir . '/other.txt', 'test');
|
||||
|
||||
// When: removeDir=true여도 보호 파일이 있으면 디렉토리 유지
|
||||
$result = deleteDirectory($this->tempDir, true);
|
||||
|
||||
// Then
|
||||
$this->assertTrue($result);
|
||||
$this->assertDirectoryExists($this->tempDir);
|
||||
$this->assertFileExists($this->tempDir . '/.gitkeep');
|
||||
$this->assertFileDoesNotExist($this->tempDir . '/other.txt');
|
||||
}
|
||||
|
||||
/**
|
||||
* deleteDirectory()가 removeDir=true이고 보호 파일이 없으면 디렉토리를 삭제하는지 확인합니다.
|
||||
*/
|
||||
public function test_removes_directory_when_no_preserve_files_and_remove_dir_true(): void
|
||||
{
|
||||
// Given: 보호 파일 없음
|
||||
file_put_contents($this->tempDir . '/file.txt', 'test');
|
||||
|
||||
// When
|
||||
$result = deleteDirectory($this->tempDir, true);
|
||||
|
||||
// Then: 디렉토리도 삭제
|
||||
$this->assertDirectoryDoesNotExist($this->tempDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* deleteDirectory()가 중첩 디렉토리를 재귀적으로 처리하는지 확인합니다.
|
||||
*/
|
||||
public function test_handles_nested_directories(): void
|
||||
{
|
||||
// Given: vendor 디렉토리 구조 시뮬레이션
|
||||
file_put_contents($this->tempDir . '/.gitkeep', '');
|
||||
mkdir($this->tempDir . '/laravel/framework/src', 0755, true);
|
||||
file_put_contents($this->tempDir . '/laravel/framework/src/Application.php', '<?php');
|
||||
file_put_contents($this->tempDir . '/autoload.php', '<?php');
|
||||
|
||||
// When
|
||||
$result = deleteDirectory($this->tempDir);
|
||||
|
||||
// Then: .gitkeep만 보존, 나머지 전부 삭제
|
||||
$this->assertTrue($result);
|
||||
$this->assertDirectoryExists($this->tempDir);
|
||||
$this->assertFileExists($this->tempDir . '/.gitkeep');
|
||||
$this->assertFileDoesNotExist($this->tempDir . '/autoload.php');
|
||||
$this->assertDirectoryDoesNotExist($this->tempDir . '/laravel');
|
||||
}
|
||||
|
||||
/**
|
||||
* deleteDirectory()가 빈 디렉토리에서도 정상 동작하는지 확인합니다.
|
||||
*/
|
||||
public function test_handles_empty_directory(): void
|
||||
{
|
||||
// When
|
||||
$result = deleteDirectory($this->tempDir);
|
||||
|
||||
// Then: 디렉토리 유지 (removeDir=false 기본값)
|
||||
$this->assertTrue($result);
|
||||
$this->assertDirectoryExists($this->tempDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* deleteDirectory()가 존재하지 않는 경로에서 false를 반환하는지 확인합니다.
|
||||
*/
|
||||
public function test_returns_false_for_nonexistent_directory(): void
|
||||
{
|
||||
$result = deleteDirectory($this->tempDir . '/nonexistent');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 임시 디렉토리를 완전히 정리합니다 (테스트용).
|
||||
*
|
||||
* @param string $dir 정리할 디렉토리 경로
|
||||
*/
|
||||
private function cleanupTempDir(string $dir): void
|
||||
{
|
||||
if (!is_dir($dir)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$items = array_diff(scandir($dir), ['.', '..']);
|
||||
foreach ($items as $item) {
|
||||
$path = $dir . DIRECTORY_SEPARATOR . $item;
|
||||
if (is_dir($path)) {
|
||||
$this->cleanupTempDir($path);
|
||||
} else {
|
||||
@unlink($path);
|
||||
}
|
||||
}
|
||||
@rmdir($dir);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Installer;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* 인스톨러 Windows 명령어 대응 테스트
|
||||
*
|
||||
* functions.php의 isWindows(), getEnvCopyCommand(), getPermissionFixCommand() 헬퍼 함수를 테스트합니다.
|
||||
*/
|
||||
class InstallerWindowsCommandsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* 테스트 전 인스톨러 설정 및 함수 파일을 로드합니다.
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
// BASE_PATH 상수가 아직 정의되지 않은 경우만 정의
|
||||
if (! defined('BASE_PATH')) {
|
||||
define('BASE_PATH', dirname(__DIR__, 2).'/..');
|
||||
}
|
||||
|
||||
// REQUIRED_DIRECTORY_PERMISSIONS 상수들이 필요
|
||||
if (! defined('REQUIRED_DIRECTORY_PERMISSIONS')) {
|
||||
define('REQUIRED_DIRECTORY_PERMISSIONS', 0770);
|
||||
}
|
||||
if (! defined('REQUIRED_DIRECTORY_PERMISSIONS_DISPLAY')) {
|
||||
define('REQUIRED_DIRECTORY_PERMISSIONS_DISPLAY', '770');
|
||||
}
|
||||
if (! defined('REQUIRED_DIRECTORIES')) {
|
||||
define('REQUIRED_DIRECTORIES', ['storage' => true]);
|
||||
}
|
||||
if (! defined('SUPPORTED_LANGUAGES')) {
|
||||
define('SUPPORTED_LANGUAGES', ['ko' => '한국어', 'en' => 'English']);
|
||||
}
|
||||
if (! defined('INSTALLER_BASE_URL')) {
|
||||
define('INSTALLER_BASE_URL', '/install');
|
||||
}
|
||||
|
||||
// functions.php 로드 (한 번만) — base_path() 대신 BASE_PATH 상수 직접 사용
|
||||
require_once BASE_PATH . '/public/install/includes/functions.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* isWindows() 함수가 현재 OS를 정확히 감지하는지 확인합니다.
|
||||
*/
|
||||
public function test_is_windows_returns_bool(): void
|
||||
{
|
||||
$result = isWindows();
|
||||
$this->assertIsBool($result);
|
||||
|
||||
// Windows 환경에서는 true여야 함
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||
$this->assertTrue($result);
|
||||
} else {
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getEnvCopyCommand()가 Windows에서 올바른 명령어를 반환하는지 확인합니다.
|
||||
*/
|
||||
public function test_get_env_copy_command_with_base_path(): void
|
||||
{
|
||||
$command = getEnvCopyCommand('/var/www/g7');
|
||||
|
||||
if (isWindows()) {
|
||||
$this->assertStringContainsString('copy', $command);
|
||||
$this->assertStringContainsString('\\', $command);
|
||||
$this->assertStringContainsString('.env.example', $command);
|
||||
$this->assertStringContainsString('.env', $command);
|
||||
} else {
|
||||
$this->assertStringContainsString('cp', $command);
|
||||
$this->assertStringContainsString('/', $command);
|
||||
$this->assertStringContainsString('.env.example', $command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getEnvCopyCommand()가 빈 경로에서도 동작하는지 확인합니다.
|
||||
*/
|
||||
public function test_get_env_copy_command_without_base_path(): void
|
||||
{
|
||||
$command = getEnvCopyCommand('');
|
||||
|
||||
if (isWindows()) {
|
||||
$this->assertStringStartsWith('copy ', $command);
|
||||
} else {
|
||||
$this->assertStringStartsWith('cp ', $command);
|
||||
}
|
||||
|
||||
$this->assertStringContainsString('.env.example', $command);
|
||||
$this->assertStringContainsString('.env', $command);
|
||||
}
|
||||
|
||||
/**
|
||||
* getPermissionFixCommand()가 Windows에서 icacls 명령어를 반환하는지 확인합니다.
|
||||
*/
|
||||
public function test_get_permission_fix_command_ownership_mode(): void
|
||||
{
|
||||
$command = getPermissionFixCommand('www-data', '/var/www/storage', 'ownership');
|
||||
|
||||
if (isWindows()) {
|
||||
$this->assertStringContainsString('icacls', $command);
|
||||
$this->assertStringContainsString('/grant', $command);
|
||||
$this->assertStringContainsString('Everyone:(OI)(CI)F', $command);
|
||||
$this->assertStringContainsString('/T', $command);
|
||||
} else {
|
||||
$this->assertStringContainsString('sudo chown -R www-data:www-data', $command);
|
||||
$this->assertStringContainsString('sudo chmod -R 2770', $command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getPermissionFixCommand()가 file 모드에서 올바른 명령어를 반환하는지 확인합니다.
|
||||
*/
|
||||
public function test_get_permission_fix_command_file_mode(): void
|
||||
{
|
||||
$command = getPermissionFixCommand('www-data', '/var/www/.env', 'file');
|
||||
|
||||
if (isWindows()) {
|
||||
$this->assertStringContainsString('icacls', $command);
|
||||
$this->assertStringContainsString('Everyone:F', $command);
|
||||
$this->assertStringNotContainsString('/T', $command);
|
||||
} else {
|
||||
$this->assertStringContainsString('sudo chown www-data:www-data', $command);
|
||||
$this->assertStringContainsString('sudo chmod 660', $command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getPermissionFixCommand()가 Windows에서 경로 구분자를 백슬래시로 변환하는지 확인합니다.
|
||||
*/
|
||||
public function test_get_permission_fix_command_windows_path_separator(): void
|
||||
{
|
||||
if (! isWindows()) {
|
||||
$this->markTestSkipped('Windows 전용 테스트');
|
||||
}
|
||||
|
||||
$command = getPermissionFixCommand('www-data', '/var/www/storage', 'ownership');
|
||||
$this->assertStringContainsString('\\var\\www\\storage', $command);
|
||||
$this->assertStringNotContainsString('/var/', $command);
|
||||
}
|
||||
|
||||
/**
|
||||
* getEnvCopyCommand()가 Windows에서 경로 구분자를 백슬래시로 변환하는지 확인합니다.
|
||||
*/
|
||||
public function test_get_env_copy_command_windows_path_separator(): void
|
||||
{
|
||||
if (! isWindows()) {
|
||||
$this->markTestSkipped('Windows 전용 테스트');
|
||||
}
|
||||
|
||||
$command = getEnvCopyCommand('C:/Users/test/htdocs/g7');
|
||||
$this->assertStringContainsString('C:\\Users\\test\\htdocs\\g7', $command);
|
||||
$this->assertStringNotContainsString('C:/Users', $command);
|
||||
}
|
||||
|
||||
/**
|
||||
* 다국어 파일에 permission_windows_hint 키가 존재하는지 확인합니다.
|
||||
*/
|
||||
public function test_translation_keys_exist(): void
|
||||
{
|
||||
$koTranslations = require BASE_PATH . '/public/install/lang/ko.php';
|
||||
$enTranslations = require BASE_PATH . '/public/install/lang/en.php';
|
||||
|
||||
$this->assertArrayHasKey('permission_windows_hint', $koTranslations, 'ko.php에 permission_windows_hint 키가 없습니다');
|
||||
$this->assertArrayHasKey('permission_windows_hint', $enTranslations, 'en.php에 permission_windows_hint 키가 없습니다');
|
||||
$this->assertNotEmpty($koTranslations['permission_windows_hint']);
|
||||
$this->assertNotEmpty($enTranslations['permission_windows_hint']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 다국어 파일에 directory_create_guide 키가 존재하는지 확인합니다.
|
||||
*/
|
||||
public function test_directory_create_guide_translation_keys_exist(): void
|
||||
{
|
||||
$koTranslations = require BASE_PATH . '/public/install/lang/ko.php';
|
||||
$enTranslations = require BASE_PATH . '/public/install/lang/en.php';
|
||||
|
||||
$this->assertArrayHasKey('directory_create_guide', $koTranslations, 'ko.php에 directory_create_guide 키가 없습니다');
|
||||
$this->assertArrayHasKey('directory_create_guide', $enTranslations, 'en.php에 directory_create_guide 키가 없습니다');
|
||||
$this->assertNotEmpty($koTranslations['directory_create_guide']);
|
||||
$this->assertNotEmpty($enTranslations['directory_create_guide']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
/**
|
||||
* deleteDirectory() 보호 파일 보존 독립 테스트 스크립트
|
||||
*
|
||||
* vendor 없이 실행 가능한 단순 테스트 러너입니다.
|
||||
* 실행: php tests/Unit/Installer/run_delete_directory_test.php
|
||||
*/
|
||||
|
||||
// 인스톨러 설정 로드
|
||||
define('BASE_PATH', dirname(__DIR__, 3));
|
||||
define('REQUIRED_DIRECTORY_PERMISSIONS', 0770);
|
||||
define('REQUIRED_DIRECTORY_PERMISSIONS_DISPLAY', '770');
|
||||
define('REQUIRED_DIRECTORIES', ['storage' => true]);
|
||||
define('SUPPORTED_LANGUAGES', ['ko' => '한국어', 'en' => 'English']);
|
||||
define('INSTALLER_BASE_URL', '/install');
|
||||
|
||||
require_once BASE_PATH . '/public/install/includes/functions.php';
|
||||
require_once BASE_PATH . '/public/install/api/rollback-functions.php';
|
||||
|
||||
$passed = 0;
|
||||
$failed = 0;
|
||||
$errors = [];
|
||||
|
||||
function assert_true($condition, $message) {
|
||||
global $passed, $failed, $errors;
|
||||
if ($condition) {
|
||||
$passed++;
|
||||
echo " ✓ {$message}\n";
|
||||
} else {
|
||||
$failed++;
|
||||
$errors[] = $message;
|
||||
echo " ✗ {$message}\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 임시 디렉토리를 완전히 정리합니다 (테스트용).
|
||||
*/
|
||||
function cleanupTempDir(string $dir): void
|
||||
{
|
||||
if (!is_dir($dir)) {
|
||||
return;
|
||||
}
|
||||
$items = array_diff(scandir($dir), ['.', '..']);
|
||||
foreach ($items as $item) {
|
||||
$path = $dir . DIRECTORY_SEPARATOR . $item;
|
||||
if (is_dir($path)) {
|
||||
cleanupTempDir($path);
|
||||
} else {
|
||||
@unlink($path);
|
||||
}
|
||||
}
|
||||
@rmdir($dir);
|
||||
}
|
||||
|
||||
echo "=== deleteDirectory() 보호 파일 보존 테스트 ===\n\n";
|
||||
|
||||
// 1. .gitkeep 파일 보존 테스트
|
||||
echo "[1] .gitkeep 파일 보존 테스트\n";
|
||||
$tempDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'g7_test_' . uniqid();
|
||||
mkdir($tempDir, 0755, true);
|
||||
file_put_contents($tempDir . '/.gitkeep', '');
|
||||
file_put_contents($tempDir . '/some_file.txt', 'test');
|
||||
mkdir($tempDir . '/subdir', 0755);
|
||||
file_put_contents($tempDir . '/subdir/nested.txt', 'test');
|
||||
|
||||
$result = deleteDirectory($tempDir);
|
||||
assert_true($result === true, 'deleteDirectory()가 true를 반환해야 합니다');
|
||||
assert_true(is_dir($tempDir), '디렉토리 자체는 유지되어야 합니다');
|
||||
assert_true(file_exists($tempDir . '/.gitkeep'), '.gitkeep 파일이 보존되어야 합니다');
|
||||
assert_true(!file_exists($tempDir . '/some_file.txt'), '일반 파일은 삭제되어야 합니다');
|
||||
assert_true(!is_dir($tempDir . '/subdir'), '하위 디렉토리는 삭제되어야 합니다');
|
||||
cleanupTempDir($tempDir);
|
||||
|
||||
// 2. .gitignore 파일 보존 테스트
|
||||
echo "\n[2] .gitignore 파일 보존 테스트\n";
|
||||
$tempDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'g7_test_' . uniqid();
|
||||
mkdir($tempDir, 0755, true);
|
||||
file_put_contents($tempDir . '/.gitignore', '*');
|
||||
file_put_contents($tempDir . '/data.log', 'log');
|
||||
|
||||
$result = deleteDirectory($tempDir);
|
||||
assert_true($result === true, 'deleteDirectory()가 true를 반환해야 합니다');
|
||||
assert_true(is_dir($tempDir), '디렉토리 자체는 유지되어야 합니다');
|
||||
assert_true(file_exists($tempDir . '/.gitignore'), '.gitignore 파일이 보존되어야 합니다');
|
||||
assert_true(!file_exists($tempDir . '/data.log'), '일반 파일은 삭제되어야 합니다');
|
||||
cleanupTempDir($tempDir);
|
||||
|
||||
// 3. removeDir=false (기본값) 시 디렉토리 유지 테스트
|
||||
echo "\n[3] removeDir=false (기본값) 시 디렉토리 유지 테스트\n";
|
||||
$tempDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'g7_test_' . uniqid();
|
||||
mkdir($tempDir, 0755, true);
|
||||
file_put_contents($tempDir . '/file1.txt', 'test');
|
||||
file_put_contents($tempDir . '/file2.txt', 'test');
|
||||
|
||||
$result = deleteDirectory($tempDir);
|
||||
assert_true($result === true, 'deleteDirectory()가 true를 반환해야 합니다');
|
||||
assert_true(is_dir($tempDir), '보호 파일 없어도 디렉토리 자체는 유지되어야 합니다 (removeDir=false)');
|
||||
assert_true(!file_exists($tempDir . '/file1.txt'), 'file1.txt는 삭제되어야 합니다');
|
||||
assert_true(!file_exists($tempDir . '/file2.txt'), 'file2.txt는 삭제되어야 합니다');
|
||||
cleanupTempDir($tempDir);
|
||||
|
||||
// 4. removeDir=true + 보호 파일 있음 → 디렉토리 유지
|
||||
echo "\n[4] removeDir=true + 보호 파일 있음 → 디렉토리 유지 테스트\n";
|
||||
$tempDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'g7_test_' . uniqid();
|
||||
mkdir($tempDir, 0755, true);
|
||||
file_put_contents($tempDir . '/.gitkeep', '');
|
||||
file_put_contents($tempDir . '/other.txt', 'test');
|
||||
|
||||
$result = deleteDirectory($tempDir, true);
|
||||
assert_true($result === true, 'deleteDirectory()가 true를 반환해야 합니다');
|
||||
assert_true(is_dir($tempDir), '보호 파일이 있으면 removeDir=true여도 디렉토리 유지');
|
||||
assert_true(file_exists($tempDir . '/.gitkeep'), '.gitkeep 파일이 보존되어야 합니다');
|
||||
assert_true(!file_exists($tempDir . '/other.txt'), '일반 파일은 삭제되어야 합니다');
|
||||
cleanupTempDir($tempDir);
|
||||
|
||||
// 5. removeDir=true + 보호 파일 없음 → 디렉토리 삭제
|
||||
echo "\n[5] removeDir=true + 보호 파일 없음 → 디렉토리 삭제 테스트\n";
|
||||
$tempDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'g7_test_' . uniqid();
|
||||
mkdir($tempDir, 0755, true);
|
||||
file_put_contents($tempDir . '/file.txt', 'test');
|
||||
|
||||
$result = deleteDirectory($tempDir, true);
|
||||
assert_true(!is_dir($tempDir), '보호 파일 없고 removeDir=true면 디렉토리도 삭제');
|
||||
// 이미 삭제됐으므로 정리 불필요
|
||||
|
||||
// 6. 중첩 디렉토리 (vendor 구조 시뮬레이션)
|
||||
echo "\n[6] vendor 디렉토리 구조 시뮬레이션 테스트\n";
|
||||
$tempDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'g7_test_' . uniqid();
|
||||
mkdir($tempDir, 0755, true);
|
||||
file_put_contents($tempDir . '/.gitkeep', '');
|
||||
mkdir($tempDir . '/laravel/framework/src', 0755, true);
|
||||
file_put_contents($tempDir . '/laravel/framework/src/Application.php', '<?php');
|
||||
file_put_contents($tempDir . '/autoload.php', '<?php');
|
||||
|
||||
$result = deleteDirectory($tempDir);
|
||||
assert_true($result === true, 'deleteDirectory()가 true를 반환해야 합니다');
|
||||
assert_true(is_dir($tempDir), 'vendor 디렉토리 자체는 유지되어야 합니다');
|
||||
assert_true(file_exists($tempDir . '/.gitkeep'), '.gitkeep 파일이 보존되어야 합니다');
|
||||
assert_true(!file_exists($tempDir . '/autoload.php'), 'autoload.php는 삭제되어야 합니다');
|
||||
assert_true(!is_dir($tempDir . '/laravel'), 'laravel 하위 디렉토리는 삭제되어야 합니다');
|
||||
cleanupTempDir($tempDir);
|
||||
|
||||
// 7. 빈 디렉토리 테스트
|
||||
echo "\n[7] 빈 디렉토리 테스트\n";
|
||||
$tempDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'g7_test_' . uniqid();
|
||||
mkdir($tempDir, 0755, true);
|
||||
|
||||
$result = deleteDirectory($tempDir);
|
||||
assert_true($result === true, 'deleteDirectory()가 true를 반환해야 합니다');
|
||||
assert_true(is_dir($tempDir), '빈 디렉토리도 유지되어야 합니다 (removeDir=false)');
|
||||
cleanupTempDir($tempDir);
|
||||
|
||||
// 8. 존재하지 않는 경로 테스트
|
||||
echo "\n[8] 존재하지 않는 경로 테스트\n";
|
||||
$result = deleteDirectory(sys_get_temp_dir() . '/g7_nonexistent_' . uniqid());
|
||||
assert_true($result === false, '존재하지 않는 경로에서 false를 반환해야 합니다');
|
||||
|
||||
// 결과 출력
|
||||
echo "\n=== 테스트 결과 ===\n";
|
||||
echo "통과: {$passed}, 실패: {$failed}\n";
|
||||
|
||||
if ($failed > 0) {
|
||||
echo "\n실패한 테스트:\n";
|
||||
foreach ($errors as $error) {
|
||||
echo " - {$error}\n";
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
echo "\n모든 테스트 통과!\n";
|
||||
exit(0);
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
/**
|
||||
* 인스톨러 Windows 명령어 대응 독립 테스트 스크립트
|
||||
*
|
||||
* vendor 없이 실행 가능한 단순 테스트 러너입니다.
|
||||
* 실행: php tests/Unit/Installer/run_test.php
|
||||
*/
|
||||
|
||||
// 인스톨러 설정 로드
|
||||
define('BASE_PATH', dirname(__DIR__, 3));
|
||||
define('REQUIRED_DIRECTORY_PERMISSIONS', 0770);
|
||||
define('REQUIRED_DIRECTORY_PERMISSIONS_DISPLAY', '770');
|
||||
define('REQUIRED_DIRECTORIES', ['storage' => true]);
|
||||
define('SUPPORTED_LANGUAGES', ['ko' => '한국어', 'en' => 'English']);
|
||||
define('INSTALLER_BASE_URL', '/install');
|
||||
|
||||
require_once BASE_PATH . '/public/install/includes/functions.php';
|
||||
|
||||
$passed = 0;
|
||||
$failed = 0;
|
||||
$errors = [];
|
||||
|
||||
function assert_true($condition, $message) {
|
||||
global $passed, $failed, $errors;
|
||||
if ($condition) {
|
||||
$passed++;
|
||||
echo " ✓ {$message}\n";
|
||||
} else {
|
||||
$failed++;
|
||||
$errors[] = $message;
|
||||
echo " ✗ {$message}\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo "=== 인스톨러 Windows 명령어 대응 테스트 ===\n\n";
|
||||
|
||||
// 1. isWindows() 테스트
|
||||
echo "[1] isWindows() 함수 테스트\n";
|
||||
$isWin = isWindows();
|
||||
assert_true(is_bool($isWin), 'isWindows()는 bool을 반환해야 합니다');
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||
assert_true($isWin === true, 'Windows 환경에서 true를 반환해야 합니다');
|
||||
} else {
|
||||
assert_true($isWin === false, 'Linux/Mac 환경에서 false를 반환해야 합니다');
|
||||
}
|
||||
|
||||
// 2. getEnvCopyCommand() 테스트 - basePath 있음
|
||||
echo "\n[2] getEnvCopyCommand() 테스트 (basePath 있음)\n";
|
||||
$cmd = getEnvCopyCommand('/var/www/g7');
|
||||
assert_true(strpos($cmd, '.env.example') !== false, '명령어에 .env.example이 포함되어야 합니다');
|
||||
assert_true(strpos($cmd, '.env') !== false, '명령어에 .env이 포함되어야 합니다');
|
||||
if ($isWin) {
|
||||
assert_true(strpos($cmd, 'copy') === 0, 'Windows에서 copy 명령어로 시작해야 합니다');
|
||||
assert_true(strpos($cmd, '\\') !== false, 'Windows에서 백슬래시 경로를 사용해야 합니다');
|
||||
} else {
|
||||
assert_true(strpos($cmd, 'cp') === 0, 'Linux에서 cp 명령어로 시작해야 합니다');
|
||||
}
|
||||
|
||||
// 3. getEnvCopyCommand() 테스트 - basePath 없음
|
||||
echo "\n[3] getEnvCopyCommand() 테스트 (basePath 없음)\n";
|
||||
$cmd2 = getEnvCopyCommand('');
|
||||
if ($isWin) {
|
||||
assert_true(strpos($cmd2, 'copy ') === 0, 'Windows에서 copy로 시작해야 합니다');
|
||||
} else {
|
||||
assert_true(strpos($cmd2, 'cp ') === 0, 'Linux에서 cp로 시작해야 합니다');
|
||||
}
|
||||
assert_true(strpos($cmd2, '.env.example') !== false, '.env.example이 포함되어야 합니다');
|
||||
|
||||
// 4. getPermissionFixCommand() 테스트 - ownership 모드
|
||||
echo "\n[4] getPermissionFixCommand() 테스트 (ownership 모드)\n";
|
||||
$permCmd = getPermissionFixCommand('www-data', '/var/www/storage', 'ownership');
|
||||
if ($isWin) {
|
||||
assert_true(strpos($permCmd, 'icacls') !== false, 'Windows에서 icacls 명령어를 사용해야 합니다');
|
||||
assert_true(strpos($permCmd, 'Everyone:(OI)(CI)F') !== false, 'Windows에서 Everyone 권한을 부여해야 합니다');
|
||||
assert_true(strpos($permCmd, '/T') !== false, 'Windows에서 /T 플래그(재귀)를 사용해야 합니다');
|
||||
assert_true(strpos($permCmd, '\\var\\www\\storage') !== false, 'Windows에서 백슬래시 경로를 사용해야 합니다');
|
||||
} else {
|
||||
assert_true(strpos($permCmd, 'sudo chgrp -R www-data') !== false, 'Linux에서 chgrp 명령어를 사용해야 합니다');
|
||||
assert_true(strpos($permCmd, 'sudo chmod -R 2770') !== false, 'Linux에서 chmod 2770을 사용해야 합니다');
|
||||
}
|
||||
|
||||
// 5. getPermissionFixCommand() 테스트 - file 모드
|
||||
echo "\n[5] getPermissionFixCommand() 테스트 (file 모드)\n";
|
||||
$filePermCmd = getPermissionFixCommand('www-data', '/var/www/.env', 'file');
|
||||
if ($isWin) {
|
||||
assert_true(strpos($filePermCmd, 'icacls') !== false, 'Windows에서 icacls 명령어를 사용해야 합니다');
|
||||
assert_true(strpos($filePermCmd, 'Everyone:F') !== false, 'Windows에서 Everyone:F 권한을 부여해야 합니다');
|
||||
assert_true(strpos($filePermCmd, '/T') === false, 'file 모드에서는 /T 플래그를 사용하지 않아야 합니다');
|
||||
} else {
|
||||
assert_true(strpos($filePermCmd, 'sudo chgrp www-data') !== false, 'Linux에서 chgrp 명령어를 사용해야 합니다');
|
||||
assert_true(strpos($filePermCmd, 'sudo chmod 660') !== false, 'Linux에서 chmod 660을 사용해야 합니다');
|
||||
}
|
||||
|
||||
// 6. 다국어 파일 번역 키 테스트
|
||||
echo "\n[6] 다국어 파일 번역 키 테스트\n";
|
||||
$koTranslations = require BASE_PATH . '/public/install/lang/ko.php';
|
||||
$enTranslations = require BASE_PATH . '/public/install/lang/en.php';
|
||||
assert_true(isset($koTranslations['permission_windows_hint']), 'ko.php에 permission_windows_hint 키가 존재해야 합니다');
|
||||
assert_true(isset($enTranslations['permission_windows_hint']), 'en.php에 permission_windows_hint 키가 존재해야 합니다');
|
||||
assert_true(!empty($koTranslations['permission_windows_hint']), 'ko.php permission_windows_hint 값이 비어있지 않아야 합니다');
|
||||
assert_true(!empty($enTranslations['permission_windows_hint']), 'en.php permission_windows_hint 값이 비어있지 않아야 합니다');
|
||||
assert_true(isset($koTranslations['directory_create_guide']), 'ko.php에 directory_create_guide 키가 존재해야 합니다');
|
||||
assert_true(isset($enTranslations['directory_create_guide']), 'en.php에 directory_create_guide 키가 존재해야 합니다');
|
||||
assert_true(!empty($koTranslations['directory_create_guide']), 'ko.php directory_create_guide 값이 비어있지 않아야 합니다');
|
||||
assert_true(!empty($enTranslations['directory_create_guide']), 'en.php directory_create_guide 값이 비어있지 않아야 합니다');
|
||||
|
||||
// 7. check-configuration.php의 .env 명령어가 OS에 맞게 생성되는지 테스트
|
||||
echo "\n[7] getEnvCopyCommand()가 check-configuration.php에서 사용되는 패턴 테스트\n";
|
||||
$basePath = BASE_PATH;
|
||||
$envCmd = getEnvCopyCommand($basePath);
|
||||
if ($isWin) {
|
||||
assert_true(strpos($envCmd, 'copy') === 0, 'check-configuration.php에서 Windows copy 명령어를 사용해야 합니다');
|
||||
// 슬래시가 백슬래시로 변환되었는지 확인
|
||||
assert_true(strpos($envCmd, '/') === false || strpos($envCmd, '\\') !== false, 'Windows에서 경로에 백슬래시가 포함되어야 합니다');
|
||||
} else {
|
||||
assert_true(strpos($envCmd, 'cp') === 0, 'check-configuration.php에서 Linux cp 명령어를 사용해야 합니다');
|
||||
}
|
||||
|
||||
// 결과 출력
|
||||
echo "\n=== 테스트 결과 ===\n";
|
||||
echo "통과: {$passed}, 실패: {$failed}\n";
|
||||
|
||||
if ($failed > 0) {
|
||||
echo "\n실패한 테스트:\n";
|
||||
foreach ($errors as $error) {
|
||||
echo " - {$error}\n";
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
echo "\n모든 테스트 통과!\n";
|
||||
exit(0);
|
||||
Reference in new issue
Block a user