Les établissements ont besoin de protéger les élèves et familles des devoirs de dernière minute. Cette configuration au niveau tenant permet de définir des règles de timing (délai minimum, pas de devoir pour lundi après une heure limite) et un mode d'application (avertissement, blocage ou désactivé). Le service de validation est prêt pour être branché dans le flux de création de devoirs (Stories 5.4/5.5). L'historique des changements assure la traçabilité des modifications de configuration.
184 lines
5.6 KiB
PHP
184 lines
5.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Functional\Administration\Api;
|
|
|
|
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
|
|
/**
|
|
* Functional tests for homework rules API endpoints.
|
|
*
|
|
* Validates routing, tenant isolation, authentication, and
|
|
* basic request/response contracts without full auth flow.
|
|
*/
|
|
final class HomeworkRulesEndpointsTest extends ApiTestCase
|
|
{
|
|
protected static ?bool $alwaysBootKernel = true;
|
|
|
|
// =========================================================================
|
|
// GET /settings/homework-rules — Without tenant
|
|
// =========================================================================
|
|
|
|
#[Test]
|
|
public function getHomeworkRulesReturns404WithoutTenant(): void
|
|
{
|
|
$client = static::createClient();
|
|
|
|
$client->request('GET', '/api/settings/homework-rules', [
|
|
'headers' => [
|
|
'Host' => 'localhost',
|
|
'Accept' => 'application/json',
|
|
],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(404);
|
|
}
|
|
|
|
// =========================================================================
|
|
// GET /settings/homework-rules — Without authentication (with tenant)
|
|
// =========================================================================
|
|
|
|
#[Test]
|
|
public function getHomeworkRulesReturns401WithoutAuthentication(): void
|
|
{
|
|
$client = static::createClient();
|
|
|
|
$client->request('GET', 'http://ecole-alpha.classeo.local/api/settings/homework-rules', [
|
|
'headers' => [
|
|
'Accept' => 'application/json',
|
|
],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(401);
|
|
}
|
|
|
|
// =========================================================================
|
|
// PUT /settings/homework-rules — Without tenant
|
|
// =========================================================================
|
|
|
|
#[Test]
|
|
public function updateHomeworkRulesReturns404WithoutTenant(): void
|
|
{
|
|
$client = static::createClient();
|
|
|
|
$client->request('PUT', '/api/settings/homework-rules', [
|
|
'headers' => [
|
|
'Host' => 'localhost',
|
|
'Accept' => 'application/json',
|
|
'Content-Type' => 'application/json',
|
|
],
|
|
'json' => [
|
|
'rules' => [],
|
|
'enforcementMode' => 'soft',
|
|
'enabled' => true,
|
|
],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(404);
|
|
}
|
|
|
|
#[Test]
|
|
public function updateHomeworkRulesReturns401WithoutAuthentication(): void
|
|
{
|
|
$client = static::createClient();
|
|
|
|
$client->request('PUT', 'http://ecole-alpha.classeo.local/api/settings/homework-rules', [
|
|
'headers' => [
|
|
'Accept' => 'application/json',
|
|
'Content-Type' => 'application/json',
|
|
],
|
|
'json' => [
|
|
'rules' => [],
|
|
'enforcementMode' => 'soft',
|
|
'enabled' => true,
|
|
],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(401);
|
|
}
|
|
|
|
// =========================================================================
|
|
// GET /settings/homework-rules/history — Without tenant / auth
|
|
// =========================================================================
|
|
|
|
#[Test]
|
|
public function getHistoryReturns404WithoutTenant(): void
|
|
{
|
|
$client = static::createClient();
|
|
|
|
$client->request('GET', '/api/settings/homework-rules/history', [
|
|
'headers' => [
|
|
'Host' => 'localhost',
|
|
'Accept' => 'application/json',
|
|
],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(404);
|
|
}
|
|
|
|
#[Test]
|
|
public function getHistoryReturns401WithoutAuthentication(): void
|
|
{
|
|
$client = static::createClient();
|
|
|
|
$client->request('GET', 'http://ecole-alpha.classeo.local/api/settings/homework-rules/history', [
|
|
'headers' => [
|
|
'Accept' => 'application/json',
|
|
],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(401);
|
|
}
|
|
|
|
// =========================================================================
|
|
// Route existence — tenant + no auth proves route exists (401 not 404)
|
|
// =========================================================================
|
|
|
|
#[Test]
|
|
public function getHomeworkRulesRouteExistsWithTenant(): void
|
|
{
|
|
$client = static::createClient();
|
|
|
|
$client->request('GET', 'http://ecole-alpha.classeo.local/api/settings/homework-rules', [
|
|
'headers' => ['Accept' => 'application/json'],
|
|
]);
|
|
|
|
// 401 (no auth) not 404 — proves route is registered
|
|
self::assertResponseStatusCodeSame(401);
|
|
}
|
|
|
|
#[Test]
|
|
public function putHomeworkRulesRouteExistsWithTenant(): void
|
|
{
|
|
$client = static::createClient();
|
|
|
|
$client->request('PUT', 'http://ecole-alpha.classeo.local/api/settings/homework-rules', [
|
|
'headers' => [
|
|
'Accept' => 'application/json',
|
|
'Content-Type' => 'application/json',
|
|
],
|
|
'json' => [
|
|
'rules' => [],
|
|
'enforcementMode' => 'soft',
|
|
'enabled' => true,
|
|
],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(401);
|
|
}
|
|
|
|
#[Test]
|
|
public function historyRouteExistsWithTenant(): void
|
|
{
|
|
$client = static::createClient();
|
|
|
|
$client->request('GET', 'http://ecole-alpha.classeo.local/api/settings/homework-rules/history', [
|
|
'headers' => ['Accept' => 'application/json'],
|
|
]);
|
|
|
|
self::assertResponseStatusCodeSame(401);
|
|
}
|
|
}
|