Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Use File Title #248

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Models/FileLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ protected function getDefaultTitle(): string
if (!$file?->exists()) {
return _t(__CLASS__ . '.MISSING_DEFAULT_TITLE', '(File missing)');
}

return (string) $this->getDescription();
return $file->Title;
}
}
3 changes: 2 additions & 1 deletion tests/behat/features/create-edit-linkfield.feature
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ I want to add links to pages, files, external URLs, email addresses and phone nu

# Fourth link in multi link field
And I should see "Link to a file" in the "[data-field-id='Form_EditForm_HasManyLinks'] .link-picker__link:nth-of-type(4)" element
And I should see "folder1/file1.jpg" in the "[data-field-id='Form_EditForm_HasManyLinks'] .link-picker__link:nth-of-type(4)" element
And I should see "File1" in the "[data-field-id='Form_EditForm_HasManyLinks'] .link-picker__link:nth-of-type(4)" element
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved
And I should see "Draft" in the "[data-field-id='Form_EditForm_HasManyLinks'] .link-picker__link:nth-of-type(4)" element

# Test that user can publish the page with links
Expand Down Expand Up @@ -203,5 +203,6 @@ I want to add links to pages, files, external URLs, email addresses and phone nu
And I wait for 2 seconds

And I should see "Link to a file" in the "[data-field-id='Form_EditForm_HasManyLinks'] .link-picker__link--is-first" element
And I should see "File1" in the "[data-field-id='Form_EditForm_HasManyLinks'] .link-picker__link--is-first" element
And I should see "folder1/file1.jpg" in the "[data-field-id='Form_EditForm_HasManyLinks'] .link-picker__link--is-first" element
And I should see "Draft" in the "[data-field-id='Form_EditForm_HasManyLinks'] .link-picker__link--is-first" element
3 changes: 2 additions & 1 deletion tests/php/Models/FileLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function testGetDefaultTitle(): void
$link = new FileLink();
$this->assertSame('(File missing)', $reflectionGetDefaultTitle->invoke($link));
// File exists in DB but not in filesystem
// Note that a 'Title' field will be derived from the 'Name' field in File::onBeforeWrite()
$file = new TestFileCanView(['Name' => 'My test file']);
$file->write();
$link->File = $file->ID;
Expand All @@ -56,6 +57,6 @@ public function testGetDefaultTitle(): void
$file->write();
$link->File = $file->ID;
$link->write();
$this->assertSame('file-b.png', $reflectionGetDefaultTitle->invoke($link));
$this->assertSame('My test file', $reflectionGetDefaultTitle->invoke($link));
}
}
2 changes: 1 addition & 1 deletion tests/php/Models/LinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ function provideDefaultLinkTitle(): array
'file link with default title' => [
'identifier' => 'file-link-with-default-title',
'class' => FileLink::class,
'expected' => '600x400.png'
'expected' => 'Image1'
],
];
}
Expand Down
Loading