172 lines
5.1 KiB
PHP
Executable File
172 lines
5.1 KiB
PHP
Executable File
<?php
|
|
|
|
/**
|
|
* Manual Test Script for Client Upload Functionality
|
|
*
|
|
* This script tests:
|
|
* 1. Upload directory existence and writability
|
|
* 2. Intervention Image availability
|
|
* 3. Model fillable fields
|
|
* 4. Controller method existence
|
|
*/
|
|
|
|
use Intervention\Image\ImageManagerStatic as Image;
|
|
|
|
echo "=== Testing Client Upload Functionality ===\n\n";
|
|
|
|
// Test 1: Check upload directory
|
|
$uploadDir = __DIR__ . '/storage/uploads/erpclients/';
|
|
echo "1. Upload Directory:\n";
|
|
echo " Path: {$uploadDir}\n";
|
|
if (is_dir($uploadDir)) {
|
|
echo " ✓ Directory exists\n";
|
|
} else {
|
|
echo " ✗ Directory does not exist\n";
|
|
exit(1);
|
|
}
|
|
|
|
if (is_writable($uploadDir)) {
|
|
echo " ✓ Directory is writable\n";
|
|
} else {
|
|
echo " ✗ Directory is not writable\n";
|
|
exit(1);
|
|
}
|
|
|
|
// Test 2: Check Intervention Image
|
|
echo "\n2. Intervention Image Library:\n";
|
|
try {
|
|
require_once __DIR__ . '/vendor/autoload.php';
|
|
|
|
// Create a simple test image
|
|
$testImage = Image::canvas(100, 100, '#ff0000');
|
|
$testPath = $uploadDir . 'test_' . time() . '.png';
|
|
$testImage->save($testPath);
|
|
|
|
if (file_exists($testPath)) {
|
|
echo " ✓ Intervention Image works correctly\n";
|
|
unlink($testPath);
|
|
} else {
|
|
echo " ✗ Failed to create test image\n";
|
|
exit(1);
|
|
}
|
|
} catch (Exception $e) {
|
|
echo " ✗ Error: " . $e->getMessage() . "\n";
|
|
exit(1);
|
|
}
|
|
|
|
// Test 3: Check Client model
|
|
echo "\n3. Client Model:\n";
|
|
try {
|
|
require_once __DIR__ . '/app/helpers.php';
|
|
require_once __DIR__ . '/kernel/Application.php';
|
|
|
|
// Initialize application
|
|
$app = new Kernel\Application();
|
|
|
|
$clientModel = new Modules\Erpclients\Models\Client();
|
|
$fillable = $clientModel->getFillable();
|
|
|
|
if (in_array('cliente_nomedaimagem', $fillable)) {
|
|
echo " ✓ cliente_nomedaimagem is fillable\n";
|
|
} else {
|
|
echo " ✗ cliente_nomedaimagem is NOT fillable\n";
|
|
exit(1);
|
|
}
|
|
|
|
if (in_array('cliente_imgcardname', $fillable)) {
|
|
echo " ✓ cliente_imgcardname is fillable\n";
|
|
} else {
|
|
echo " ✗ cliente_imgcardname is NOT fillable\n";
|
|
exit(1);
|
|
}
|
|
|
|
echo " ✓ Client model is correctly configured\n";
|
|
} catch (Exception $e) {
|
|
echo " ✗ Error: " . $e->getMessage() . "\n";
|
|
exit(1);
|
|
}
|
|
|
|
// Test 4: Check Controller method
|
|
echo "\n4. Client Controller:\n";
|
|
try {
|
|
$controller = new Modules\Erpclients\Controllers\ClientController($app->getView());
|
|
$reflection = new \ReflectionClass($controller);
|
|
|
|
if ($reflection->hasMethod('handleFileUploads')) {
|
|
$method = $reflection->getMethod('handleFileUploads');
|
|
if ($method->isPrivate()) {
|
|
echo " ✓ handleFileUploads method exists and is private\n";
|
|
} else {
|
|
echo " ✗ handleFileUploads exists but is not private\n";
|
|
exit(1);
|
|
}
|
|
} else {
|
|
echo " ✗ handleFileUploads method does not exist\n";
|
|
exit(1);
|
|
}
|
|
} catch (Exception $e) {
|
|
echo " ✗ Error: " . $e->getMessage() . "\n";
|
|
exit(1);
|
|
}
|
|
|
|
// Test 5: Check translation files
|
|
echo "\n5. Translation Files:\n";
|
|
$languages = ['pt_BR', 'en_US', 'es_ES', 'de_DE', 'fr_FR'];
|
|
$requiredKeys = [
|
|
'images_section',
|
|
'main_image',
|
|
'card_image',
|
|
'image_help',
|
|
'current_main_image',
|
|
'replace_main_image',
|
|
'current_card_image',
|
|
'replace_card_image'
|
|
];
|
|
|
|
foreach ($languages as $lang) {
|
|
$translationFile = __DIR__ . "/modules/erpclients/locales/{$lang}/erpclients.json";
|
|
if (file_exists($translationFile)) {
|
|
$content = json_decode(file_get_contents($translationFile), true);
|
|
if (isset($content['form'])) {
|
|
$missingKeys = array_diff($requiredKeys, array_keys($content['form']));
|
|
if (empty($missingKeys)) {
|
|
echo " ✓ {$lang}: All upload keys present\n";
|
|
} else {
|
|
echo " ✗ {$lang}: Missing keys: " . implode(', ', $missingKeys) . "\n";
|
|
exit(1);
|
|
}
|
|
} else {
|
|
echo " ✗ {$lang}: 'form' section not found\n";
|
|
exit(1);
|
|
}
|
|
} else {
|
|
echo " ✗ {$lang}: Translation file not found\n";
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
// Test 6: Check view files
|
|
echo "\n6. View Files:\n";
|
|
$views = [
|
|
'create.twig' => __DIR__ . '/modules/erpclients/views/admin/clients/create.twig',
|
|
'edit.twig' => __DIR__ . '/modules/erpclients/views/admin/clients/edit.twig',
|
|
'index.twig' => __DIR__ . '/modules/erpclients/views/admin/clients/index.twig'
|
|
];
|
|
|
|
foreach ($views as $name => $path) {
|
|
if (file_exists($path)) {
|
|
$content = file_get_contents($path);
|
|
if (strpos($content, 'cliente_nomedaimagem') !== false || strpos($content, 'storage/uploads/erpclients') !== false) {
|
|
echo " ✓ {$name}: Contains upload fields\n";
|
|
} else {
|
|
echo " ⚠ {$name}: May not have upload functionality\n";
|
|
}
|
|
} else {
|
|
echo " ✗ {$name}: File not found\n";
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
echo "\n=== All Tests Passed! ===\n";
|
|
echo "The client upload functionality is correctly implemented.\n";
|