VvvebJs / test-github-storage.php
CatPtain's picture
Upload 5 files
92a44b9 verified
<?php
// Test script to verify GitHub directory creation and file saving
require_once 'storage.php';
echo "Testing GitHub Storage Directory Creation and File Saving...\n";
// Initialize GitHub storage
$storage = new GitHubStorage();
// Test 1: Verify configuration
echo "1. Checking GitHub configuration...\n";
if (!$storage->isConfigured()) {
echo "ERROR: GitHub storage is not properly configured.\n";
echo "Please check your GitHub token and repository settings.\n";
exit(1);
}
echo "βœ“ GitHub configuration is valid.\n";
// Test 2: Test directory creation
echo "2. Testing directory creation...\n";
$userPath = $storage->getUserPath();
if (!$userPath) {
echo "ERROR: Could not determine user path.\n";
exit(1);
}
echo "User path: $userPath\n";
// Test 3: Test file saving
echo "3. Testing file save...\n";
$testContent = "<!DOCTYPE html>\n<html>\n<head>\n<title>Test Page</title>\n</head>\n<body>\n<h1>Test Content</h1>\n<p>This is a test file created at " . date('Y-m-d H:i:s') . "</p>\n</body>\n</html>";
$testFilename = "test-" . date('YmdHis') . ".html";
$result = $storage->save($testFilename, $testContent);
if ($result) {
echo "βœ“ File saved successfully: $testFilename\n";
// Test 4: Verify file can be loaded
echo "4. Testing file load...\n";
$loadedContent = $storage->load($testFilename);
if ($loadedContent === $testContent) {
echo "βœ“ File loaded successfully and content matches.\n";
} else {
echo "WARNING: File loaded but content doesn't match exactly.\n";
echo "Expected length: " . strlen($testContent) . "\n";
echo "Actual length: " . strlen($loadedContent) . "\n";
}
} else {
echo "ERROR: Failed to save test file.\n";
exit(1);
}
echo "\nAll tests completed successfully!\n";
?>