Fixup FilesystemService document filename generation.

There was a missing '.' before extension
This commit is contained in:
Benoît Burnichon
2016-02-12 19:15:54 +01:00
parent d1e1d18f8a
commit 1d519ff58f
2 changed files with 52 additions and 3 deletions

View File

@@ -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());
}
/**

View File

@@ -0,0 +1,48 @@
<?php
/**
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Tests\Phrasea\Filesystem;
use Alchemy\Phrasea\Filesystem\FilesystemService;
use Alchemy\Phrasea\Model\RecordInterface;
use Symfony\Component\Filesystem\Filesystem;
class FilesystemServiceTest extends \PHPUnit_Framework_TestCase
{
/**
* @var FilesystemService
*/
private $sut;
protected function setUp()
{
$this->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')],
];
}
}