Add Event entity, create event page, and custom WYSIWYG editor component

- Create Event entity with fields: account, title, description (text), startAt, endAt, address, zipcode, city, eventMainPicture (VichUploader), isOnline, createdAt, updatedAt
- Create EventRepository
- Add migration for event table with all columns
- Add "Creer un evenement" button on account events tab
- Add create event page (/mon-compte/evenement/creer) with full form
- Build custom web component <e-ticket-editor> WYSIWYG editor:
  - Toolbar: bold, italic, underline, paragraph, bullet list, remove formatting
  - contentEditable div with HTML sync to hidden textarea
  - HTML sanitizer (strips disallowed tags, XSS safe)
  - Neo-brutalist CSS styling
  - CSP compliant (no inline styles)
- Register editor in app.js via customElements.define
- Add editor CSS in app.scss
- Add 16 Event entity tests (all fields + isOnline + picture upload + updatedAt)
- Add 16 editor JS tests (sanitizer + custom element lifecycle)
- Add 3 AccountController tests (create event page, submit, access control)
- Update placeholders to generic examples (no association-specific data)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serreau Jovann
2026-03-20 12:49:24 +01:00
parent ffa6e04a2e
commit 8b3b1dab13
12 changed files with 911 additions and 0 deletions

View File

@@ -467,6 +467,54 @@ class AccountControllerTest extends WebTestCase
self::assertNotNull($user->getLogoName());
}
public function testCreateEventPageRequiresOrganizer(): void
{
$client = static::createClient();
$user = $this->createUser();
$client->loginUser($user);
$client->request('GET', '/mon-compte/evenement/creer');
self::assertResponseStatusCodeSame(403);
}
public function testCreateEventPageReturnsSuccess(): void
{
$client = static::createClient();
$user = $this->createUser(['ROLE_ORGANIZER'], true);
$client->loginUser($user);
$client->request('GET', '/mon-compte/evenement/creer');
self::assertResponseIsSuccessful();
}
public function testCreateEventSubmit(): void
{
$client = static::createClient();
$em = static::getContainer()->get(EntityManagerInterface::class);
$user = $this->createUser(['ROLE_ORGANIZER'], true);
$client->loginUser($user);
$client->request('POST', '/mon-compte/evenement/creer', [
'title' => 'Convention Test',
'description' => 'Un super evenement',
'start_at' => '2026-07-01T10:00',
'end_at' => '2026-07-01T18:00',
'address' => '42 rue de Saint-Quentin',
'zipcode' => '02800',
'city' => 'Beautor',
]);
self::assertResponseRedirects('/mon-compte?tab=events');
$event = $em->getRepository(\App\Entity\Event::class)->findOneBy(['title' => 'Convention Test']);
self::assertNotNull($event);
self::assertSame($user->getId(), $event->getAccount()->getId());
self::assertSame('Un super evenement', $event->getDescription());
self::assertSame('Beautor', $event->getCity());
}
/**
* @param list<string> $roles
*/

155
tests/Entity/EventTest.php Normal file
View File

@@ -0,0 +1,155 @@
<?php
namespace App\Tests\Entity;
use App\Entity\Event;
use App\Entity\User;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\File\File;
class EventTest extends TestCase
{
public function testNewEventHasNullId(): void
{
$event = new Event();
self::assertNull($event->getId());
}
public function testCreatedAtIsSetOnConstruction(): void
{
$event = new Event();
self::assertInstanceOf(\DateTimeImmutable::class, $event->getCreatedAt());
}
public function testSetAndGetAccount(): void
{
$event = new Event();
$user = new User();
$user->setEmail('orga@example.com');
$user->setFirstName('Test');
$user->setLastName('Orga');
$user->setPassword('hashed');
$result = $event->setAccount($user);
self::assertSame($user, $event->getAccount());
self::assertSame($event, $result);
}
public function testSetAndGetTitle(): void
{
$event = new Event();
$result = $event->setTitle('Brocante de printemps 2026');
self::assertSame('Brocante de printemps 2026', $event->getTitle());
self::assertSame($event, $result);
}
public function testSetAndGetStartAt(): void
{
$event = new Event();
$date = new \DateTimeImmutable('2026-06-15 10:00:00');
$result = $event->setStartAt($date);
self::assertSame($date, $event->getStartAt());
self::assertSame($event, $result);
}
public function testSetAndGetEndAt(): void
{
$event = new Event();
$date = new \DateTimeImmutable('2026-06-15 18:00:00');
$result = $event->setEndAt($date);
self::assertSame($date, $event->getEndAt());
self::assertSame($event, $result);
}
public function testSetAndGetDescription(): void
{
$event = new Event();
$result = $event->setDescription('Grande brocante avec stands et animations.');
self::assertSame('Grande brocante avec stands et animations.', $event->getDescription());
self::assertSame($event, $result);
}
public function testDescriptionIsNullByDefault(): void
{
$event = new Event();
self::assertNull($event->getDescription());
}
public function testSetAndGetAddress(): void
{
$event = new Event();
$result = $event->setAddress('12 avenue de la Republique');
self::assertSame('12 avenue de la Republique', $event->getAddress());
self::assertSame($event, $result);
}
public function testSetAndGetZipcode(): void
{
$event = new Event();
$result = $event->setZipcode('75011');
self::assertSame('75011', $event->getZipcode());
self::assertSame($event, $result);
}
public function testSetAndGetCity(): void
{
$event = new Event();
$result = $event->setCity('Paris');
self::assertSame('Paris', $event->getCity());
self::assertSame($event, $result);
}
public function testSetAndGetEventMainPictureName(): void
{
$event = new Event();
$result = $event->setEventMainPictureName('event-photo.jpg');
self::assertSame('event-photo.jpg', $event->getEventMainPictureName());
self::assertSame($event, $result);
}
public function testSetEventMainPictureFileUpdatesTimestamp(): void
{
$event = new Event();
self::assertNull($event->getUpdatedAt());
$file = $this->createMock(File::class);
$result = $event->setEventMainPictureFile($file);
self::assertSame($file, $event->getEventMainPictureFile());
self::assertInstanceOf(\DateTimeImmutable::class, $event->getUpdatedAt());
self::assertSame($event, $result);
}
public function testIsOnlineDefaultFalse(): void
{
$event = new Event();
self::assertFalse($event->isOnline());
}
public function testSetAndGetIsOnline(): void
{
$event = new Event();
$result = $event->setIsOnline(true);
self::assertTrue($event->isOnline());
self::assertSame($event, $result);
}
public function testSetEventMainPictureFileNullDoesNotUpdateTimestamp(): void
{
$event = new Event();
$event->setEventMainPictureFile(null);
self::assertNull($event->getUpdatedAt());
self::assertNull($event->getEventMainPictureFile());
}
}

117
tests/js/editor.test.js Normal file
View File

@@ -0,0 +1,117 @@
import { describe, it, expect, beforeEach } from 'vitest'
import { sanitizeHtml, ETicketEditor, registerEditor } from '../../assets/modules/editor.js'
describe('sanitizeHtml', () => {
it('keeps allowed tags', () => {
const html = '<p>Hello <b>world</b></p>'
expect(sanitizeHtml(html)).toBe('<p>Hello <b>world</b></p>')
})
it('strips disallowed tags but keeps content', () => {
const html = '<div><span>Hello</span></div>'
expect(sanitizeHtml(html)).toBe('Hello')
})
it('strips links but keeps text', () => {
const html = '<a href="https://example.com">Link</a>'
expect(sanitizeHtml(html)).toBe('Link')
})
it('keeps list elements', () => {
const html = '<ul><li>Item 1</li><li>Item 2</li></ul>'
expect(sanitizeHtml(html)).toBe('<ul><li>Item 1</li><li>Item 2</li></ul>')
})
it('strips blockquote but keeps content', () => {
const html = '<blockquote>Citation</blockquote>'
expect(sanitizeHtml(html)).toBe('Citation')
})
it('returns empty string for empty input', () => {
expect(sanitizeHtml('')).toBe('')
})
it('strips headings but keeps content', () => {
const html = '<h2>Title</h2><h3>Subtitle</h3>'
expect(sanitizeHtml(html)).toBe('TitleSubtitle')
})
it('strips style attributes from allowed tags', () => {
const html = '<p style="color:red">Text</p>'
expect(sanitizeHtml(html)).toBe('<p>Text</p>')
})
})
function createEditor(innerHtml = '<textarea></textarea>') {
registerEditor()
document.body.innerHTML = ''
const el = document.createElement('e-ticket-editor')
el.innerHTML = innerHtml
document.body.appendChild(el)
el.connectedCallback()
return el
}
describe('ETicketEditor', () => {
beforeEach(() => {
registerEditor()
})
it('registers the custom element', () => {
expect(globalThis.customElements.get('e-ticket-editor')).toBe(ETicketEditor)
})
it('hides the textarea and creates toolbar + content area', () => {
const editor = createEditor('<textarea placeholder="Ecrivez ici...">Hello</textarea>')
const textarea = editor.querySelector('textarea')
const toolbar = editor.querySelector('.ete-toolbar')
const content = editor.querySelector('.ete-content')
expect(textarea.style.display).toBe('none')
expect(toolbar).not.toBeNull()
expect(content).not.toBeNull()
expect(content.getAttribute('contenteditable')).toBe('true')
expect(content.innerHTML).toBe('Hello')
expect(content.dataset.placeholder).toBe('Ecrivez ici...')
})
it('does nothing without a textarea', () => {
const editor = createEditor('')
expect(editor.querySelector('.ete-toolbar')).toBeNull()
expect(editor.querySelector('.ete-content')).toBeNull()
})
it('toolbar has buttons', () => {
const editor = createEditor()
const buttons = editor.querySelectorAll('.ete-btn')
expect(buttons.length).toBeGreaterThan(0)
})
it('toolbar has separators', () => {
const editor = createEditor()
const separators = editor.querySelectorAll('.ete-separator')
expect(separators.length).toBeGreaterThan(0)
})
it('getHtml returns textarea value', () => {
const editor = createEditor('<textarea>Content</textarea>')
expect(editor.getHtml()).toBe('Content')
})
it('prevents tab key default in content area', () => {
const editor = createEditor()
const content = editor.querySelector('.ete-content')
const event = new KeyboardEvent('keydown', { key: 'Tab', cancelable: true })
content.dispatchEvent(event)
expect(event.defaultPrevented).toBe(true)
})
it('allows non-tab keys', () => {
const editor = createEditor()
const content = editor.querySelector('.ete-content')
const event = new KeyboardEvent('keydown', { key: 'Enter', cancelable: true })
content.dispatchEvent(event)
expect(event.defaultPrevented).toBe(false)
})
})