[Miscellaneous] [Regex] Use simpler & stronger pattern to match name of file

This commit is contained in:
Meritoo
2019-12-18 20:25:06 +01:00
parent 872259e63d
commit ddb3f0a544
5 changed files with 16 additions and 9 deletions

View File

@@ -94,11 +94,14 @@ class MiscellaneousTest extends BaseTestCase
self::assertEquals($withoutExtension, Miscellaneous::getFileNameWithoutExtension($fileName));
}
public function testGetFileNameFromPath()
public function testGetFileNameFromPath(): void
{
// Path with file
self::assertEquals('sit.amet.JPG', Miscellaneous::getFileNameFromPath('lorem/ipsum-dolor/sit.amet.JPG'));
// Path with complicated name of file
self::assertEquals('this-1_2 3 & my! 4+file.jpg', Miscellaneous::getFileNameFromPath('lorem/ipsum-dolor/this-1_2 3 & my! 4+file.jpg'));
// Path without file
self::assertEquals('', Miscellaneous::getFileNameFromPath('lorem/ipsum-dolor/sit-amet'));

View File

@@ -244,13 +244,16 @@ class RegexTest extends BaseTestCase
self::assertTrue(Regex::contains($this->simpleText, 'l'));
}
public function testIsFileName()
public function testIsFileName(): void
{
$filePath = __FILE__;
$directoryPath = dirname($filePath);
self::assertTrue(Regex::isFileName($filePath));
self::assertTrue(Regex::isFileName('this-1_2 3 & my! 4+file.jpg'));
self::assertFalse(Regex::isFileName($directoryPath));
self::assertTrue(Regex::isFileName('directory1/directory2/this-1_2 3 & my! 4+file.jpg'));
}
public function testIsQuoted()