First Commit

This commit is contained in:
marco
2026-09-01 10:46:29 -03:00
commit bf96b77e9c
10000 changed files with 3508600 additions and 0 deletions
+121
View File
@@ -0,0 +1,121 @@
<?php
namespace Tests;
use PHPUnit\Framework\TestCase;
use Kernel\Application;
use Illuminate\Database\Capsule\Manager as Capsule;
/**
* Base class for SysCMS Module Testing
*/
abstract class ModuleTestCase extends TestCase
{
protected Application $app;
protected string $moduleName = '';
protected function setUp(): void
{
parent::setUp();
// Ensure Application is initialized
if (Application::getInstance() === null) {
new Application();
}
$this->app = Application::getInstance();
}
/**
* Asserts that all translation keys are present in all 5 supported languages
*/
protected function assertTranslationsComplete(string $module): void
{
$languages = ['pt_BR', 'en_US', 'es_ES', 'de_DE', 'fr_FR'];
$basePath = dirname(__DIR__) . "/modules/{$module}/locales";
if (!is_dir($basePath)) {
$this->fail("Locales directory not found for module: {$module}");
}
$keys = [];
foreach ($languages as $lang) {
$file = "{$basePath}/{$lang}/{$module}.json";
if (!file_exists($file)) {
$this->fail("Translation file missing for language {$lang} in module {$module}");
}
$content = json_decode(file_get_contents($file), true);
$keys[$lang] = array_keys($this->flattenArray($content));
}
$referenceKeys = $keys['pt_BR'];
foreach ($languages as $lang) {
$diff = array_diff($referenceKeys, $keys[$lang]);
$this->assertEmpty($diff, "Missing translation keys in {$lang} for module {$module}: " . implode(', ', $diff));
}
}
/**
* Asserts that a route exists in the system
*/
protected function assertRouteExists(string $method, string $uri): void
{
$routes = $this->app->getRoutes();
$found = false;
foreach ($routes as $route) {
if ($route[0] === strtoupper($method) && $route[1] === $uri) {
$found = true;
break;
}
}
$this->assertTrue($found, "Route [{$method}] {$uri} not found.");
}
/**
* Verifies if a table exists and has specific data
*/
protected function assertDatabaseHas(string $table, array $data): void
{
$query = Capsule::table($table);
foreach ($data as $key => $value) {
$query->where($key, $value);
}
$this->assertGreaterThan(0, $query->count(), "Data not found in table {$table}");
}
/**
* Verifies if a table does not have specific data
*/
protected function assertDatabaseMissing(string $table, array $data): void
{
$query = Capsule::table($table);
foreach ($data as $key => $value) {
$query->where($key, $value);
}
$this->assertEquals(0, $query->count(), "Data found in table {$table} when it should be missing");
}
/**
* Verifies the count of records in a table
*/
protected function assertDatabaseCount(string $table, int $count): void
{
$this->assertEquals($count, Capsule::table($table)->count(), "Table {$table} does not have {$count} records");
}
/**
* Helper to flatten nested translation arrays
*/
private function flattenArray(array $array, string $prefix = ''): array
{
$result = [];
foreach ($array as $key => $value) {
$newKey = $prefix . (empty($prefix) ? '' : '.') . $key;
if (is_array($value)) {
$result = array_merge($result, $this->flattenArray($value, $newKey));
} else {
$result[$newKey] = $value;
}
}
return $result;
}
}
+124
View File
@@ -0,0 +1,124 @@
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
use Illuminate\Database\Capsule\Manager as Capsule;
use Modules\Blog\Models\Category;
use Modules\Blog\Models\Post;
use Modules\Blog\Models\Comment;
class BlogTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
$capsule->setAsGlobal();
$capsule->bootEloquent();
// Create tables with correct primary keys for Eloquent models
Capsule::schema()->create('blog_categories', function ($table) {
$table->id('categories_id'); // Match $primaryKey = 'categories_id'
$table->string('categories_name');
$table->string('categories_slug');
$table->text('categories_description')->nullable();
$table->timestamps();
});
Capsule::schema()->create('blog_posts', function ($table) {
$table->id('posts_id'); // Match $primaryKey = 'posts_id'
$table->foreignId('posts_category_id')->nullable(); // Match $fillable 'posts_category_id'
$table->foreignId('posts_author_id')->nullable();
$table->integer('posts_bus_id')->default(1);
$table->string('posts_title');
$table->string('posts_slug');
$table->text('posts_content');
$table->enum('posts_status', ['draft', 'published'])->default('draft');
$table->string('posts_visibility')->default('public');
$table->timestamps();
});
Capsule::schema()->create('blog_comments', function ($table) {
$table->id('comments_id'); // Match $primaryKey = 'comments_id'
$table->foreignId('comments_post_id'); // Match $fillable 'comments_post_id'
$table->foreignId('comments_user_id')->nullable();
$table->string('comments_author_name');
$table->string('comments_author_email');
$table->text('comments_content');
$table->enum('comments_status', ['pending', 'approved', 'spam'])->default('pending');
$table->timestamps();
$table->softDeletes();
});
}
public function test_can_create_category()
{
$category = Category::create([
'categories_name' => 'Tech',
'categories_slug' => 'tech',
'categories_description' => 'Technology news'
]);
$this->assertNotNull($category->categories_id);
$this->assertEquals('Tech', $category->categories_name);
}
public function test_can_create_post_with_category()
{
$category = Category::create([
'categories_name' => 'Tech',
'categories_slug' => 'tech'
]);
$post = Post::create([
'posts_category_id' => $category->categories_id,
'posts_author_id' => 1,
'posts_title' => 'New PHP Version',
'posts_slug' => 'new-php-version',
'posts_content' => 'PHP 8.2 is out!',
'posts_status' => 'published'
]);
$this->assertNotNull($post->posts_id);
$this->assertEquals($category->categories_id, $post->posts_category_id);
$this->assertEquals('New PHP Version', $post->posts_title);
}
public function test_can_create_comment_on_post()
{
$category = Category::create([
'categories_name' => 'Tech',
'categories_slug' => 'tech'
]);
$post = Post::create([
'posts_category_id' => $category->categories_id,
'posts_author_id' => 1,
'posts_title' => 'New PHP Version',
'posts_slug' => 'new-php-version',
'posts_content' => 'PHP 8.2 is out!',
'posts_status' => 'published'
]);
$comment = Comment::create([
'comments_post_id' => $post->posts_id,
'comments_author_name' => 'John Doe',
'comments_author_email' => 'john@example.com',
'comments_content' => 'Great post!',
'comments_status' => 'approved'
]);
$this->assertNotNull($comment->comments_id);
$this->assertEquals($post->posts_id, $comment->comments_post_id);
$this->assertEquals('John Doe', $comment->comments_author_name);
}
}
+18
View File
@@ -0,0 +1,18 @@
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function test_that_true_is_true(): void
{
$this->assertTrue(true);
}
}
+10
View File
@@ -0,0 +1,10 @@
<?php
use Kernel\ModuleLoader;
require __DIR__ . '/../vendor/autoload.php';
// Register Module Autoloader
// Note: We use relative path from tests/ directory to modules/
$moduleLoader = new ModuleLoader(__DIR__ . '/../modules');
$moduleLoader->registerAutoload();
+171
View File
@@ -0,0 +1,171 @@
<?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";