mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX Files without extensions (folders) do not have a trailing period added
This commit is contained in:
parent
7f5ca56e36
commit
2f579b64cb
@ -634,7 +634,7 @@ class File extends DataObject {
|
|||||||
*
|
*
|
||||||
* Does not change the filesystem itself, please use {@link write()} for this.
|
* Does not change the filesystem itself, please use {@link write()} for this.
|
||||||
*
|
*
|
||||||
* @param String $name
|
* @param string $name
|
||||||
*/
|
*/
|
||||||
public function setName($name) {
|
public function setName($name) {
|
||||||
$oldName = $this->Name;
|
$oldName = $this->Name;
|
||||||
@ -663,7 +663,10 @@ class File extends DataObject {
|
|||||||
))->first()
|
))->first()
|
||||||
) {
|
) {
|
||||||
$suffix++;
|
$suffix++;
|
||||||
$name = "$base-$suffix.$ext";
|
$name = "$base-$suffix";
|
||||||
|
if (!empty($ext)) {
|
||||||
|
$name .= ".$ext";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,6 +187,30 @@ class FileTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses fixtures Folder.folder1 and File.setfromname
|
||||||
|
* @dataProvider setNameFileProvider
|
||||||
|
*/
|
||||||
|
public function testSetNameAddsUniqueSuffixWhenFilenameAlreadyExists($name, $expected)
|
||||||
|
{
|
||||||
|
$duplicate = new Folder;
|
||||||
|
$duplicate->setName($name);
|
||||||
|
$duplicate->write();
|
||||||
|
|
||||||
|
$this->assertSame($expected, $duplicate->Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array[]
|
||||||
|
*/
|
||||||
|
public function setNameFileProvider()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('FileTest-folder1', 'FileTest-folder1-2'),
|
||||||
|
array('FileTest.png', 'FileTest-2.png'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function testLinkAndRelativeLink() {
|
public function testLinkAndRelativeLink() {
|
||||||
$file = $this->objFromFixture('File', 'asdf');
|
$file = $this->objFromFixture('File', 'asdf');
|
||||||
$this->assertEquals(ASSETS_DIR . '/FileTest.txt', $file->RelativeLink());
|
$this->assertEquals(ASSETS_DIR . '/FileTest.txt', $file->RelativeLink());
|
||||||
|
Loading…
Reference in New Issue
Block a user