From 1d519ff58fdc1a960020dfd11cb88ec95ce0431c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Burnichon?= Date: Fri, 12 Feb 2016 19:15:54 +0100 Subject: [PATCH] Fixup FilesystemService document filename generation. There was a missing '.' before extension --- .../Phrasea/Filesystem/FilesystemService.php | 7 +-- .../Filesystem/FilesystemServiceTest.php | 48 +++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 tests/Alchemy/Tests/Phrasea/Filesystem/FilesystemServiceTest.php diff --git a/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php b/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php index b6b34894ce..1ec7c39880 100644 --- a/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php +++ b/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php @@ -10,6 +10,7 @@ namespace Alchemy\Phrasea\Filesystem; +use Alchemy\Phrasea\Model\RecordInterface; use MediaAlchemyst\Specification\SpecificationInterface; class FilesystemService @@ -66,17 +67,17 @@ class FilesystemService } /** - * @param \record_adapter $record + * @param RecordInterface $record * @param string|\SplFileInfo $source * @return string */ - public function generateDocumentFilename(\record_adapter $record, $source) + public function generateDocumentFilename(RecordInterface $record, $source) { if (!$source instanceof \SplFileInfo) { $source = new \SplFileInfo($source); } - return $record->getRecordId() . '_document' . strtolower($source->getExtension()); + return $record->getRecordId() . '_document.' . strtolower($source->getExtension()); } /** diff --git a/tests/Alchemy/Tests/Phrasea/Filesystem/FilesystemServiceTest.php b/tests/Alchemy/Tests/Phrasea/Filesystem/FilesystemServiceTest.php new file mode 100644 index 0000000000..daa522a4dc --- /dev/null +++ b/tests/Alchemy/Tests/Phrasea/Filesystem/FilesystemServiceTest.php @@ -0,0 +1,48 @@ +sut = new FilesystemService(new Filesystem()); + } + + /** + * @dataProvider provideRecordsAndExpectedDocumentFilenames + */ + public function testItProperlyGeneratesDocumentFileNames($expected, $recordId, $filename) + { + $record = $this->prophesize(RecordInterface::class); + $record->getRecordId()->willReturn($recordId); + + $this->assertEquals($expected, $this->sut->generateDocumentFilename($record->reveal(), $filename)); + } + + public function provideRecordsAndExpectedDocumentFileNames() + { + return [ + ['2_document.jpg', 2, 'foo.jpg'], + ['42_document.jpg', 42, 'bar.JPG'], + ['2_document.pdf', 2, new \SplFileInfo('foo_bar.pdf')], + ]; + } +}