Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ef1188d

Browse filesBrowse files
Add support for custom regex in SlugValidator tests
Enhanced the SlugValidator tests to include validation for custom regex patterns. Added cases to verify both valid and invalid slugs based on a user-defined regex, ensuring more flexibility in slug validation.
1 parent 0193d0c commit ef1188d
Copy full SHA for ef1188d

File tree

Expand file treeCollapse file tree

1 file changed

+29
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+29
-0
lines changed

‎src/Symfony/Component/Validator/Tests/Constraints/SlugValidatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/SlugValidatorTest.php
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,33 @@ public function testInvalidSlugs($slug)
7474
->setCode(Slug::NOT_SLUG_ERROR)
7575
->assertRaised();
7676
}
77+
78+
/**
79+
* @testWith ["test-slug", true]
80+
* ["slug-123-test", true]
81+
*/
82+
public function testCustomRegexInvalidSlugs($slug)
83+
{
84+
$constraint = new Slug(regex: '/^[a-z0-9]+$/i');
85+
86+
$this->validator->validate($slug, $constraint);
87+
88+
$this->buildViolation($constraint->message)
89+
->setParameter('{{ value }}', '"'.$slug.'"')
90+
->setCode(Slug::NOT_SLUG_ERROR)
91+
->assertRaised();
92+
}
93+
94+
/**
95+
* @testWith ["slug"]
96+
* @testWith ["test1234"]
97+
*/
98+
public function testCustomRegexValidSlugs($slug)
99+
{
100+
$constraint = new Slug(regex: '/^[a-z0-9]+$/i');
101+
102+
$this->validator->validate($slug, $constraint);
103+
104+
$this->assertNoViolation();
105+
}
77106
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.