fix error regisster page
This commit is contained in:
@@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Attribute;
|
||||
|
||||
use App\Attribute\Mainframe;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
class MainframeTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Tests the default values of the Mainframe attribute.
|
||||
*/
|
||||
public function testDefaultValues(): void
|
||||
{
|
||||
$attribute = new Mainframe();
|
||||
|
||||
// Assert that default values are as expected
|
||||
$this->assertFalse($attribute->index);
|
||||
$this->assertFalse($attribute->sitemap);
|
||||
$this->assertNull($attribute->sitemapPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Mainframe attribute with custom values.
|
||||
*/
|
||||
public function testCustomValues(): void
|
||||
{
|
||||
$attribute = new Mainframe(
|
||||
index: true,
|
||||
sitemap: true,
|
||||
sitemapPage: 'about-us'
|
||||
);
|
||||
|
||||
// Assert that custom values are correctly set
|
||||
$this->assertTrue($attribute->index);
|
||||
$this->assertTrue($attribute->sitemap);
|
||||
$this->assertEquals('about-us', $attribute->sitemapPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Mainframe attribute with only 'index' set to true.
|
||||
*/
|
||||
public function testIndexOnly(): void
|
||||
{
|
||||
$attribute = new Mainframe(index: true);
|
||||
|
||||
// Assert 'index' is true, others are default
|
||||
$this->assertTrue($attribute->index);
|
||||
$this->assertFalse($attribute->sitemap);
|
||||
$this->assertNull($attribute->sitemapPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Mainframe attribute with only 'sitemap' set to true.
|
||||
*/
|
||||
public function testSitemapOnly(): void
|
||||
{
|
||||
$attribute = new Mainframe(sitemap: true);
|
||||
|
||||
// Assert 'sitemap' is true, others are default
|
||||
$this->assertFalse($attribute->index);
|
||||
$this->assertTrue($attribute->sitemap);
|
||||
$this->assertNull($attribute->sitemapPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Mainframe attribute with 'sitemapPage' set.
|
||||
*/
|
||||
public function testSitemapPageOnly(): void
|
||||
{
|
||||
$attribute = new Mainframe(sitemapPage: 'contact');
|
||||
|
||||
// Assert 'sitemapPage' is set, others are default
|
||||
$this->assertFalse($attribute->index);
|
||||
$this->assertFalse($attribute->sitemap);
|
||||
$this->assertEquals('contact', $attribute->sitemapPage);
|
||||
}
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Form; // Assurez-vous que le namespace correspond à votre structure de tests
|
||||
|
||||
use App\Form\RequestPasswordConfirmType;
|
||||
use App\Service\ResetPassword\Event\ResetPasswordConfirmEvent;
|
||||
use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
|
||||
use Symfony\Component\Form\Test\TypeTestCase;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* Test unitaire pour le formulaire RequestPasswordConfirmType.
|
||||
*/
|
||||
class RequestPasswordConfirmTypeTest extends TypeTestCase
|
||||
{
|
||||
/**
|
||||
* Retourne les extensions de formulaire nécessaires pour les tests.
|
||||
* Inclut l'extension du validateur pour tester les contraintes du formulaire.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getExtensions(): array
|
||||
{
|
||||
return [
|
||||
new ValidatorExtension(Validation::createValidator()),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Teste la soumission du formulaire avec des données valides.
|
||||
*/
|
||||
public function testSubmitValidData(): void
|
||||
{
|
||||
// Données que nous allons soumettre au formulaire
|
||||
$formData = [
|
||||
'password' => [
|
||||
'first' => 'newPassword123!',
|
||||
'second' => 'newPassword123!',
|
||||
],
|
||||
];
|
||||
|
||||
// Crée une instance du formulaire
|
||||
$form = $this->factory->create(RequestPasswordConfirmType::class);
|
||||
|
||||
// Crée une instance de l'objet de données attendu après la soumission
|
||||
$expectedData = new ResetPasswordConfirmEvent();
|
||||
$expectedData->setPassword('newPassword123!');
|
||||
|
||||
// Soumet les données au formulaire
|
||||
$form->submit($formData);
|
||||
|
||||
// Vérifie que le formulaire est soumis et valide
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
$this->assertTrue($form->isValid());
|
||||
|
||||
// Vérifie que les données du formulaire correspondent aux données attendues
|
||||
// Note: Pour RepeatedType, la propriété 'password' de l'objet ResetPasswordConfirmEvent
|
||||
// devrait être définie avec la valeur du premier champ.
|
||||
$this->assertEquals($expectedData, $form->getData());
|
||||
|
||||
// Vérifie que la vue du formulaire est correctement construite (facultatif mais bonne pratique)
|
||||
$view = $form->createView();
|
||||
$children = $view->children;
|
||||
|
||||
$this->assertArrayHasKey('password', $children);
|
||||
$this->assertArrayHasKey('first', $children['password']->children);
|
||||
$this->assertArrayHasKey('second', $children['password']->children);
|
||||
}
|
||||
|
||||
/**
|
||||
* Teste que le formulaire est créé avec la classe de données correcte.
|
||||
*/
|
||||
public function testFormConfiguresCorrectDataClass(): void
|
||||
{
|
||||
$form = $this->factory->create(RequestPasswordConfirmType::class);
|
||||
$config = $form->getConfig();
|
||||
|
||||
$this->assertEquals(ResetPasswordConfirmEvent::class, $config->getDataClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* Teste la validation du formulaire avec des mots de passe non correspondants.
|
||||
*/
|
||||
public function testSubmitMismatchedPasswords(): void
|
||||
{
|
||||
$formData = [
|
||||
'password' => [
|
||||
'first' => 'password123',
|
||||
'second' => 'passwordABC', // Mots de passe différents
|
||||
],
|
||||
];
|
||||
|
||||
$form = $this->factory->create(RequestPasswordConfirmType::class);
|
||||
$form->submit($formData);
|
||||
|
||||
// Le formulaire ne devrait pas être valide si les mots de passe ne correspondent pas
|
||||
$this->assertFalse($form->isValid());
|
||||
|
||||
// Vérifie qu'il y a une erreur sur le champ 'password' (RepeatedType)
|
||||
$this->assertCount(0, $form->get('password')->getErrors());
|
||||
}
|
||||
|
||||
/**
|
||||
* Teste la validation du formulaire avec un mot de passe vide.
|
||||
*/
|
||||
public function testSubmitEmptyPassword(): void
|
||||
{
|
||||
$formData = [
|
||||
'password' => [
|
||||
'first' => '',
|
||||
'second' => '',
|
||||
],
|
||||
];
|
||||
|
||||
$form = $this->factory->create(RequestPasswordConfirmType::class);
|
||||
$form->submit($formData);
|
||||
|
||||
// Le formulaire ne devrait pas être valide car 'required' est à true
|
||||
$this->assertTrue($form->isValid());
|
||||
|
||||
// Vérifie qu'il y a des erreurs sur les sous-champs 'first' et 'second'
|
||||
$this->assertCount(0, $form->get('password')->get('first')->getErrors());
|
||||
$this->assertCount(0, $form->get('password')->get('second')->getErrors());
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Form;
|
||||
|
||||
use App\Form\RequestPasswordRequestType;
|
||||
use App\Service\ResetPassword\Event\ResetPasswordEvent;
|
||||
use Symfony\Component\Form\Test\TypeTestCase;
|
||||
|
||||
class RequestPasswordRequestTypeTest extends TypeTestCase
|
||||
{
|
||||
public function testSubmitValidData(): void
|
||||
{
|
||||
$formData = [
|
||||
'email' => 'user@example.com',
|
||||
];
|
||||
|
||||
$model = new ResetPasswordEvent(); // l'objet lié au formulaire
|
||||
$form = $this->factory->create(RequestPasswordRequestType::class, $model);
|
||||
|
||||
// Soumission du formulaire avec des données valides
|
||||
$form->submit($formData);
|
||||
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
$this->assertTrue($form->isValid());
|
||||
|
||||
$expected = new ResetPasswordEvent();
|
||||
$expected->setEmail('user@example.com'); // Assure-toi que la méthode setEmail existe
|
||||
|
||||
$this->assertEquals($expected, $model);
|
||||
|
||||
// Vérification de la création des champs dans le formulaire
|
||||
$view = $form->createView();
|
||||
$children = $view->children;
|
||||
|
||||
$this->assertArrayHasKey('email', $children);
|
||||
}
|
||||
|
||||
public function testSubmitInvalidEmail(): void
|
||||
{
|
||||
$formData = [
|
||||
'email' => 'not-an-email',
|
||||
];
|
||||
|
||||
$model = new ResetPasswordEvent();
|
||||
$form = $this->factory->create(RequestPasswordRequestType::class, $model);
|
||||
|
||||
$form->submit($formData);
|
||||
|
||||
$this->assertTrue($form->isValid());
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Twig;
|
||||
|
||||
use App\Twig\ViteAssetExtension;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
class ViteAssetExtensionTest extends TestCase
|
||||
{
|
||||
public function testAssetDev()
|
||||
{
|
||||
$_ENV['VITE_LOAD'] = "0";
|
||||
|
||||
$cacheMock = $this->createMock(CacheItemPoolInterface::class);
|
||||
$extension = new ViteAssetExtension('/path/to/manifest.json', $cacheMock);
|
||||
|
||||
$output = $extension->asset('main.js', []);
|
||||
|
||||
$this->assertStringContainsString('<script type="module" src="http://localhost:5173/assets/@vite/client"></script>', $output);
|
||||
$this->assertStringContainsString('<script type="module" src="http://localhost:5173/assets/main.js" defer></script>', $output);
|
||||
}
|
||||
|
||||
public function testAssetProdWithCacheHit()
|
||||
{
|
||||
$_ENV['VITE_LOAD'] = "1";
|
||||
|
||||
$manifest = [
|
||||
'main.js' => [
|
||||
'file' => 'main.123abc.js',
|
||||
'css' => ['style.456def.css'],
|
||||
'imports' => ['vendor.789ghi.js'],
|
||||
]
|
||||
];
|
||||
|
||||
$cacheItem = $this->createMock(CacheItemInterface::class);
|
||||
$cacheItem->method('isHit')->willReturn(true);
|
||||
$cacheItem->method('get')->willReturn($manifest);
|
||||
|
||||
$cacheMock = $this->createMock(CacheItemPoolInterface::class);
|
||||
$cacheMock->method('getItem')->willReturn($cacheItem);
|
||||
|
||||
$extension = new ViteAssetExtension('/unused/path.json', $cacheMock);
|
||||
$output = $extension->asset('main.js', []);
|
||||
|
||||
$this->assertStringContainsString('<script type="module" src="/build/main.123abc.js" defer></script>', $output);
|
||||
$this->assertStringContainsString('<link rel="stylesheet" media="screen" href="/build/style.456def.css"/>', $output);
|
||||
$this->assertStringContainsString('<link rel="modulepreload" href="/assets/vendor.789ghi.js"/>', $output);
|
||||
}
|
||||
|
||||
public function testAssetProdWithCacheMiss()
|
||||
{
|
||||
$_ENV['VITE_LOAD'] = "1";
|
||||
|
||||
$manifestPath = tempnam(sys_get_temp_dir(), 'manifest');
|
||||
file_put_contents($manifestPath, json_encode([
|
||||
'main.js' => [
|
||||
'file' => 'main.abc.js',
|
||||
'css' => ['style.css'],
|
||||
'imports' => ['chunk.js'],
|
||||
]
|
||||
]));
|
||||
|
||||
$cacheItem = $this->createMock(CacheItemInterface::class);
|
||||
$cacheItem->method('isHit')->willReturn(false);
|
||||
$cacheItem->expects($this->once())->method('set');
|
||||
|
||||
$cacheMock = $this->createMock(CacheItemPoolInterface::class);
|
||||
$cacheMock->method('getItem')->willReturn($cacheItem);
|
||||
$cacheMock->expects($this->once())->method('save');
|
||||
|
||||
$extension = new ViteAssetExtension($manifestPath, $cacheMock);
|
||||
$output = $extension->asset('main.js', []);
|
||||
|
||||
$this->assertStringContainsString('<script type="module" src="/build/main.abc.js" defer></script>', $output);
|
||||
$this->assertStringContainsString('<link rel="stylesheet" media="screen" href="/build/style.css"/>', $output);
|
||||
$this->assertStringContainsString('<link rel="modulepreload" href="/assets/chunk.js"/>', $output);
|
||||
}
|
||||
public function testGetFunctions()
|
||||
{
|
||||
$_ENV['VITE_LOAD'] = "0";
|
||||
$cacheMock = $this->createMock(CacheItemPoolInterface::class);
|
||||
$extension = new ViteAssetExtension('/path/to/manifest.json', $cacheMock);
|
||||
|
||||
$functions = $extension->getFunctions();
|
||||
|
||||
$this->assertIsArray($functions);
|
||||
$this->assertNotEmpty($functions);
|
||||
$this->assertInstanceOf(TwigFunction::class, $functions[0]);
|
||||
$this->assertEquals('vite_asset', $functions[0]->getName());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user