Sindbad~EG File Manager

Current Path : /home/copmadinaarea/.trash/
Upload File :
Current File : /home/copmadinaarea/.trash/test_proofreading_workflow.php

<?php
require_once 'config/config.php';
require_once 'classes/Editorial.php';
require_once 'classes/News.php';

if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
if (!isset($_SESSION['user_id'])) {
    die('Please login to test the proofreading workflow.');
}

$database = new Database();
$conn = $database->getConnection();
$editorial = new Editorial($conn);
$news = new News($conn);

echo "<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Proofreading Workflow Test - COP News Portal</title>
    <link rel='stylesheet' href='assets/css/style.css'>
    <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css'>
    <style>
        .test-section { margin: 2rem 0; padding: 1.5rem; border: 1px solid var(--light-grey); border-radius: 8px; }
        .test-result { padding: 1rem; margin: 1rem 0; border-radius: 6px; }
        .test-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
        .test-error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
        .test-info { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }
        .test-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeaa7; }
        pre { background: #f8f9fa; padding: 1rem; border-radius: 4px; overflow-x: auto; }
    </style>
</head>
<body>
    <header class='header'>
        <nav class='navbar'>
            <a href='dashboard.php' class='logo'>
                <i class='fas fa-church'></i> COP News Portal - Testing
            </a>
        </nav>
    </header>
    
    <main class='container' style='margin-top: 2rem;'>
        <div class='card'>
            <div class='card-header'>
                <h1><i class='fas fa-vial'></i> Proofreading Workflow Test Suite</h1>
                <p>Testing user: <strong>" . htmlspecialchars($_SESSION['user_name']) . "</strong> (" . htmlspecialchars($_SESSION['account_type']) . ")</p>
            </div>
            <div class='card-body'>";

// Test 1: Database Schema Verification
echo "<div class='test-section'>
        <h2><i class='fas fa-database'></i> Test 1: Database Schema Verification</h2>";

$schema_tests = [
    "SELECT COUNT(*) as count FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'users' AND column_name = 'editorial_scope'" => "Editorial scope column in users table",
    "SELECT COUNT(*) as count FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'news' AND column_name = 'assigned_editor_id'" => "Assigned editor column in news table",
    "SELECT COUNT(*) as count FROM information_schema.TABLES WHERE table_schema = DATABASE() AND table_name = 'news_reviews'" => "News reviews table exists",
    "SELECT COUNT(*) as count FROM information_schema.TABLES WHERE table_schema = DATABASE() AND table_name = 'editor_assignments'" => "Editor assignments table exists",
    "SELECT COUNT(*) as count FROM information_schema.TABLES WHERE table_schema = DATABASE() AND table_name = 'review_notifications'" => "Review notifications table exists"
];

foreach ($schema_tests as $query => $description) {
    try {
        $stmt = $conn->prepare($query);
        $stmt->execute();
        $result = $stmt->fetch(PDO::FETCH_ASSOC);
        
        if ($result['count'] > 0) {
            echo "<div class='test-result test-success'><i class='fas fa-check'></i> $description: PASSED</div>";
        } else {
            echo "<div class='test-result test-error'><i class='fas fa-times'></i> $description: FAILED</div>";
        }
    } catch (Exception $e) {
        echo "<div class='test-result test-error'><i class='fas fa-times'></i> $description: ERROR - " . $e->getMessage() . "</div>";
    }
}

echo "</div>";

// Test 2: Sample Editor Users
echo "<div class='test-section'>
        <h2><i class='fas fa-users'></i> Test 2: Sample Editor Users</h2>";

try {
    $stmt = $conn->prepare("SELECT id, username, name, account_type, editorial_scope FROM users WHERE account_type = 'editor'");
    $stmt->execute();
    $editors = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    if (count($editors) > 0) {
        echo "<div class='test-result test-success'><i class='fas fa-check'></i> Found " . count($editors) . " editor users</div>";
        echo "<table class='table'><thead><tr><th>ID</th><th>Username</th><th>Name</th><th>Scope</th></tr></thead><tbody>";
        foreach ($editors as $editor) {
            echo "<tr><td>{$editor['id']}</td><td>{$editor['username']}</td><td>{$editor['name']}</td><td>{$editor['editorial_scope']}</td></tr>";
        }
        echo "</tbody></table>";
    } else {
        echo "<div class='test-result test-warning'><i class='fas fa-exclamation-triangle'></i> No editor users found. Run migration script first.</div>";
    }
} catch (Exception $e) {
    echo "<div class='test-result test-error'><i class='fas fa-times'></i> Error checking editors: " . $e->getMessage() . "</div>";
}

echo "</div>";

// Test 3: Editorial Class Methods
echo "<div class='test-section'>
        <h2><i class='fas fa-code'></i> Test 3: Editorial Class Methods</h2>";

$methods_to_test = [
    'submitForReview',
    'reviewArticle',
    'publishArticle',
    'getReviewQueue',
    'getApprovedArticles',
    'getEditorialStats',
    'findAssignedEditor',
    'canUserReview',
    'canUserPublish'
];

foreach ($methods_to_test as $method) {
    if (method_exists($editorial, $method)) {
        echo "<div class='test-result test-success'><i class='fas fa-check'></i> Method '$method' exists</div>";
    } else {
        echo "<div class='test-result test-error'><i class='fas fa-times'></i> Method '$method' missing</div>";
    }
}

echo "</div>";

// Test 4: Create Test Article and Submit for Review
echo "<div class='test-section'>
        <h2><i class='fas fa-newspaper'></i> Test 4: Article Submission Workflow</h2>";

try {
    // First, get a valid location ID from the database
    $location_stmt = $conn->prepare("SELECT id FROM locations LIMIT 1");
    $location_stmt->execute();
    $valid_location = $location_stmt->fetch(PDO::FETCH_ASSOC);
    
    if (!$valid_location) {
        echo "<div class='test-result test-error'><i class='fas fa-times'></i> No locations found in database</div>";
    } else {
        // Create a test article
        $test_article_data = [
            'title' => 'Test Article for Proofreading - ' . date('Y-m-d H:i:s'),
            'location_id' => $valid_location['id'], // Use valid location ID
            'description' => 'This is a test article to verify the proofreading workflow functionality.',
            'content' => '<p>This is the content of our test article. It contains some <strong>formatted text</strong> and demonstrates the proofreading system.</p><p>The article should be submitted for review and then processed by an editor.</p>',
            'written_by' => $_SESSION['user_name'],
            'category_id' => null,
            'user_id' => $_SESSION['user_id'],
            'status' => 'draft',
            'featured_image' => null
        ];
    
    $test_news_id = $news->create($test_article_data);
    
    if ($test_news_id) {
        echo "<div class='test-result test-success'><i class='fas fa-check'></i> Test article created with ID: $test_news_id</div>";
        
        // Submit for review
        $review_result = $editorial->submitForReview($test_news_id, $_SESSION['user_id']);
        
        if ($review_result['success']) {
            echo "<div class='test-result test-success'><i class='fas fa-check'></i> Article submitted for review successfully</div>";
            echo "<div class='test-result test-info'><i class='fas fa-info'></i> Assigned Editor ID: " . ($review_result['assigned_editor_id'] ?? 'Auto-assigned') . "</div>";
        } else {
            echo "<div class='test-result test-error'><i class='fas fa-times'></i> Failed to submit for review: " . $review_result['error'] . "</div>";
        }
    } else {
        echo "<div class='test-result test-error'><i class='fas fa-times'></i> Failed to create test article</div>";
    }
    }
} catch (Exception $e) {
    echo "<div class='test-result test-error'><i class='fas fa-times'></i> Error in article submission test: " . $e->getMessage() . "</div>";
}

echo "</div>";

// Test 5: Editorial Statistics
echo "<div class='test-section'>
        <h2><i class='fas fa-chart-bar'></i> Test 5: Editorial Statistics</h2>";

try {
    $stats = $editorial->getEditorialStats();
    echo "<div class='test-result test-success'><i class='fas fa-check'></i> Editorial statistics retrieved</div>";
    echo "<pre>" . json_encode($stats, JSON_PRETTY_PRINT) . "</pre>";
} catch (Exception $e) {
    echo "<div class='test-result test-error'><i class='fas fa-times'></i> Error getting statistics: " . $e->getMessage() . "</div>";
}

echo "</div>";

// Test 6: Review Queue
echo "<div class='test-section'>
        <h2><i class='fas fa-list-check'></i> Test 6: Review Queue</h2>";

try {
    $queue = $editorial->getReviewQueue($_SESSION['user_id']);
    echo "<div class='test-result test-success'><i class='fas fa-check'></i> Review queue retrieved: " . count($queue) . " articles</div>";
    
    if (count($queue) > 0) {
        echo "<table class='table'><thead><tr><th>ID</th><th>Title</th><th>Author</th><th>Status</th><th>Submitted</th></tr></thead><tbody>";
        foreach (array_slice($queue, 0, 5) as $article) {
            echo "<tr>";
            echo "<td>{$article['id']}</td>";
            echo "<td>" . htmlspecialchars(substr($article['title'], 0, 50)) . "...</td>";
            echo "<td>{$article['author_name']}</td>";
            echo "<td>{$article['status']}</td>";
            echo "<td>" . ($article['submitted_for_review_at'] ? date('M j, Y', strtotime($article['submitted_for_review_at'])) : 'N/A') . "</td>";
            echo "</tr>";
        }
        echo "</tbody></table>";
    }
} catch (Exception $e) {
    echo "<div class='test-result test-error'><i class='fas fa-times'></i> Error getting review queue: " . $e->getMessage() . "</div>";
}

echo "</div>";

// Test 7: User Permissions
echo "<div class='test-section'>
        <h2><i class='fas fa-shield-alt'></i> Test 7: User Permissions</h2>";

try {
    $can_review = $editorial->canUserReview($_SESSION['user_id']);
    $can_publish = $editorial->canUserPublish($_SESSION['user_id']);
    
    echo "<div class='test-result " . ($can_review ? 'test-success' : 'test-info') . "'>";
    echo "<i class='fas fa-" . ($can_review ? 'check' : 'info') . "'></i> ";
    echo "Current user " . ($can_review ? 'CAN' : 'CANNOT') . " review articles</div>";
    
    echo "<div class='test-result " . ($can_publish ? 'test-success' : 'test-info') . "'>";
    echo "<i class='fas fa-" . ($can_publish ? 'check' : 'info') . "'></i> ";
    echo "Current user " . ($can_publish ? 'CAN' : 'CANNOT') . " publish articles</div>";
} catch (Exception $e) {
    echo "<div class='test-result test-error'><i class='fas fa-times'></i> Error checking permissions: " . $e->getMessage() . "</div>";
}

echo "</div>";

// Test Summary
echo "<div class='test-section'>
        <h2><i class='fas fa-clipboard-check'></i> Test Summary & Next Steps</h2>
        <div class='test-result test-info'>
            <h3>Manual Testing Steps:</h3>
            <ol>
                <li><strong>Login as Editor:</strong> Use credentials editor_accra/editor123 or editor_tema/editor123</li>
                <li><strong>Access Editorial Dashboard:</strong> Navigate to <code>editorial/dashboard.php</code></li>
                <li><strong>Review Articles:</strong> Check the review queue and approve/reject test articles</li>
                <li><strong>Publish Articles:</strong> Go to approved articles and publish them</li>
                <li><strong>Test Notifications:</strong> Verify that review actions create proper notifications</li>
                <li><strong>Test Location-based Assignment:</strong> Create articles from different locations and verify proper editor assignment</li>
            </ol>
            
            <h3>URLs to Test:</h3>
            <ul>
                <li><a href='editorial/dashboard.php' target='_blank'>Editorial Dashboard</a></li>
                <li><a href='editorial/approved.php' target='_blank'>Approved Articles</a></li>
                <li><a href='news/create.php' target='_blank'>Create News (with review option)</a></li>
                <li><a href='news/index.php' target='_blank'>News Index</a></li>
            </ul>
        </div>
      </div>";

echo "    </div>
        </div>
    </main>
</body>
</html>";
?>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists