Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #3100 from tractorcow/pulls/3.0-fix-foldername

FIX Folder Title not being exactly the same as Name field
  • Loading branch information...
commit 0099a18182fe45aebc3ecb030d7a1161676534b5 2 parents 0ae96ab + ad27cd5
@tractorcow tractorcow authored
View
14 filesystem/File.php
@@ -603,19 +603,19 @@ public function setName($name) {
}
}
- // Update title
- if(!$this->getField('Title')) {
- $this->__set('Title', str_replace(array('-','_'),' ', preg_replace('/\.[^.]+$/', '', $name)));
- }
-
// Update actual field value
$this->setField('Name', $name);
// Ensure that the filename is updated as well (only in-memory)
// Important: Circumvent the getter to avoid infinite loops
$this->setField('Filename', $this->getRelativePath());
-
- return $this->getField('Name');
+
+ // Update title
+ if(!$this->Title) {
+ $this->Title = str_replace(array('-','_'),' ', preg_replace('/\.[^.]+$/', '', $name));
+ }
+
+ return $name;
}
/**
View
9 filesystem/Folder.php
@@ -334,13 +334,16 @@ public function onBeforeDelete() {
* Note that this is not appropriate for files, because someone might want to create a human-readable name
* of a file that is different from its name on disk. But folders should always match their name on disk. */
public function setTitle($title) {
- $this->setField('Title',$title);
- parent::setName($title); //set the name and filename to match the title
+ $this->setName($title);
+ }
+
+ public function getTitle() {
+ return $this->Name;
}
public function setName($name) {
- $this->setField('Title',$name);
parent::setName($name);
+ $this->setField('Title', $this->Name);
}
public function setFilename($filename) {
View
17 tests/filesystem/FolderTest.php
@@ -293,5 +293,20 @@ public function tearDown() {
parent::tearDown();
}
-
+
+ public function testTitleTiedToName() {
+ $newFolder = new Folder();
+
+ $newFolder->Name = 'TestNameCopiedToTitle';
+ $this->assertEquals($newFolder->Name, $newFolder->Title);
+
+ $newFolder->Title = 'TestTitleCopiedToName';
+ $this->assertEquals($newFolder->Name, $newFolder->Title);
+
+ $newFolder->Name = 'TestNameWithIllegalCharactersCopiedToTitle <!BANG!>';
+ $this->assertEquals($newFolder->Name, $newFolder->Title);
+
+ $newFolder->Title = 'TestTitleWithIllegalCharactersCopiedToName <!BANG!>';
+ $this->assertEquals($newFolder->Name, $newFolder->Title);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.