Skip to content

Commit

Permalink
Merge pull request #166 from open-sausages/pulls/1/sort-it-out
Browse files Browse the repository at this point in the history
BUG Keep folder Name and Title in sync on update
  • Loading branch information
robbieaverill authored Oct 8, 2018
2 parents 787a48b + 1a08051 commit 6d67489
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ public function onBeforeDelete()
parent::onBeforeDelete();
}

public function onBeforeWrite()
{
parent::onBeforeWrite();

$this->Title = $this->getField('Name');
}

/**
* Return the relative URL of an icon for this file type
*
Expand Down
13 changes: 13 additions & 0 deletions tests/php/FolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,19 @@ public function testTitleTiedToName()
$newFolder->Title = 'TestTitleWithIllegalCharactersCopiedToName <!BANG!>';
$this->assertEquals($newFolder->Name, $newFolder->Title);
$this->assertEquals($newFolder->Title, 'TestTitleWithIllegalCharactersCopiedToName <!BANG!>');

// Title should be populated from name on first write
$writeFolder = new Folder();
$writeFolder->Name = 'TestNameWrittenToTitle';
$writeFolder->write();
$newFolderWritten = Folder::get_one(Folder::class, "\"Title\" = 'TestNameWrittenToTitle'");
$this->assertNotNull($newFolderWritten);

// Title should be populated from name on subsequent writes
$writeFolder->Name = 'TestNameWrittenToTitleOnUpdate';
$writeFolder->write();
$newFolderWritten = Folder::get_one(Folder::class, "\"Title\" = 'TestNameWrittenToTitleOnUpdate'");
$this->assertNotNull($newFolderWritten);
}

public function testRootFolder()
Expand Down

0 comments on commit 6d67489

Please sign in to comment.