Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/Content/View/Filter/ContentEditViewFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function handleContentEditForm(FilterViewBuilderParametersEvent $event):

$event->getParameters()->add([
'form' => $form->handleRequest($request),
'validate' => (bool)$request->get('validate', false),
'validate' => $request->query->getBoolean('validate'),
]);
}

Expand Down
21 changes: 20 additions & 1 deletion src/lib/Validator/Constraints/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,36 @@
namespace Ibexa\ContentForms\Validator\Constraints;

use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
use Symfony\Component\Validator\Attribute\HasNamedArguments;
use Symfony\Component\Validator\Constraint;

/**
* @Annotation
*/
class Password extends Constraint
{
public string $message = 'ez.user.password.invalid';
protected const string MESSAGE = 'ez.user.password.invalid';

public string $message = self::MESSAGE;

public ?ContentType $contentType;

/**
* @param array<string>|null $groups
*/
#[HasNamedArguments]
public function __construct(
?ContentType $contentType = null,
?string $message = null,
?array $groups = null,
mixed $payload = null
) {
parent::__construct(null, $groups, $payload);

$this->contentType = $contentType;
$this->message = $message ?? static::MESSAGE;
}

public function getTargets(): array
{
return [self::CLASS_CONSTRAINT, self::PROPERTY_CONSTRAINT];
Expand Down
22 changes: 22 additions & 0 deletions tests/lib/Validator/Constraints/PasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@

use Ibexa\ContentForms\Validator\Constraints\Password;
use Ibexa\ContentForms\Validator\Constraints\PasswordValidator;
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
use PHPUnit\Framework\TestCase;

/**
* @covers \Ibexa\ContentForms\Validator\Constraints\Password
*/
final class PasswordTest extends TestCase
{
private Password $constraint;
Expand Down Expand Up @@ -41,4 +45,22 @@ public function testGetTargets(): void
$this->constraint->getTargets()
);
}

public function testNamedArguments(): void
{
$contentType = $this->createMock(ContentType::class);
$payload = new \stdClass();

$constraint = new Password(
contentType: $contentType,
message: 'Custom message',
groups: ['custom'],
payload: $payload
);

self::assertSame($contentType, $constraint->contentType);
self::assertSame('Custom message', $constraint->message);
self::assertSame(['custom'], $constraint->groups);
self::assertSame($payload, $constraint->payload);
}
}
8 changes: 2 additions & 6 deletions tests/lib/Validator/Constraints/PasswordValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ public function testValid(): void
->expects(self::never())
->method('buildViolation');

$this->validator->validate($password, new Password([
'contentType' => $contentType,
]));
$this->validator->validate($password, new Password(contentType: $contentType));
}

public function testInvalid(): void
Expand Down Expand Up @@ -117,9 +115,7 @@ public function testInvalid(): void
->expects(self::once())
->method('addViolation');

$this->validator->validate('pass', new Password([
'contentType' => $contentType,
]));
$this->validator->validate('pass', new Password(contentType: $contentType));
}

public function dataProviderForValidateNotSupportedValueType(): array
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/Validator/Constraints/UserAccountPasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Ibexa\ContentForms\Validator\Constraints\UserAccountPassword;
use Ibexa\ContentForms\Validator\Constraints\UserAccountPasswordValidator;
use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Constraint;

Expand All @@ -36,4 +37,13 @@ public function testGetTargets(): void
{
self::assertSame([Constraint::CLASS_CONSTRAINT, Constraint::PROPERTY_CONSTRAINT], $this->constraint->getTargets());
}

public function testNamedArguments(): void
{
$contentType = $this->createMock(ContentType::class);

$constraint = new UserAccountPassword(contentType: $contentType);

self::assertSame($contentType, $constraint->contentType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ public function testValid(): void
->expects(self::never())
->method('buildViolation');

$this->validator->validate($userAccount, new UserAccountPassword([
'contentType' => $contentType,
]));
$this->validator->validate($userAccount, new UserAccountPassword(contentType: $contentType));
}

public function testInvalid(): void
Expand Down Expand Up @@ -126,8 +124,6 @@ public function testInvalid(): void
->expects(self::once())
->method('addViolation');

$this->validator->validate($userAccount, new UserAccountPassword([
'contentType' => $contentType,
]));
$this->validator->validate($userAccount, new UserAccountPassword(contentType: $contentType));
}
}
Loading