diff --git a/library/Class/File/Info.php b/library/Class/File/Info.php index 452a13b3ff3024065398951e93cfc7c5c5b2b8fe..9d057a78270653030a67ea552c4619a4b3d134de 100644 --- a/library/Class/File/Info.php +++ b/library/Class/File/Info.php @@ -20,21 +20,28 @@ */ class Class_File_Info { - protected $_filepath; + protected + $_filepath, + $_path_info; /** @param filepath string */ public function __construct($filepath) { $this->_filepath = (string)$filepath; + $this->_path_info = $this->_filepath + ? pathinfo($this->_filepath) + : ['dirname' => '', + 'basename' => '', + 'filename' => '', + 'extension' => '']; } - public function humanizeFilename() { if (!$file = $this->fileNameWithoutExtension()) return ''; $parts = array_filter(preg_split('/[^a-zA-Z\s]+/', $file)); - return implode(' ', array_map('trim',$parts)); + return ucfirst(implode(' ', array_map('trim',$parts))); } @@ -42,9 +49,33 @@ class Class_File_Info { * @return string */ public function fileNameWithoutExtension() { - return $this->_filepath - ? pathinfo($this->_filepath)['filename'] - : ''; + return $this->_path_info['filename']; + } + + + /** + * @return string + */ + public function fileNameWithExtension() { + return $this->_path_info['basename']; + } + + + /** + * @return string + */ + public function fileExtension() { + return $this->_path_info['extension']; + } + + + /** + * @return string + */ + public function fileSize() { + return file_exists($this->_filepath) + ? filesize($this->_filepath) + : 0; } } diff --git a/library/ZendAfi/View/Helper/AlbumRessourceInfos.php b/library/ZendAfi/View/Helper/AlbumRessourceInfos.php index de47833add7188a83533d55ad3544941d33fb60e..d635ee66f5babba9c3b7e92b91868c6bbd2864a7 100644 --- a/library/ZendAfi/View/Helper/AlbumRessourceInfos.php +++ b/library/ZendAfi/View/Helper/AlbumRessourceInfos.php @@ -21,12 +21,10 @@ class ZendAfi_View_Helper_AlbumRessourceInfos extends Zend_View_Helper_HtmlElement { public function albumRessourceInfos($ressource) { - $infos = $this->view->fileInfos($ressource->getOriginalPath()); - - if (!$ressource->hasTitre()) - return $infos; - - return $ressource->getTitre().'<br/>'.$infos; + $file_info = new Class_File_Info($ressource->getOriginalPath()); + return $ressource->findTitle() + .'<br/>' + .'['.$file_info->fileExtension().', '.$this->view->memoryFormat($file_info->fileSize()).']'; } } diff --git a/library/ZendAfi/View/Helper/FileInfos.php b/library/ZendAfi/View/Helper/FileInfos.php index 36ca529c9cc7379b3694846eaee5d926c3f52b78..6df62644d8020eea86bd56fedfd744e27cbac0d8 100644 --- a/library/ZendAfi/View/Helper/FileInfos.php +++ b/library/ZendAfi/View/Helper/FileInfos.php @@ -24,41 +24,8 @@ class ZendAfi_View_Helper_FileInfos extends Zend_View_Helper_Abstract { * @return string */ public function fileInfos($path) { - return $this->fileName($path) . $this->fileSize($path); - } - - - /** - * @param string $path - * @return string - */ - public function fileName($path) { - $parts = explode('/', $path); - return end($parts); - } - - - /** - * @param string $path - * @return string - */ - public function fileExtension($path) { - $parts = explode('.', $path); - return '.' . end($parts); - } - - - /** - * @param string $path - * @return string - */ - public function fileSize($path) { - if (!file_exists($path)) { - return ''; - } - - $size = filesize($path); - return ', ' . $this->view->memoryFormat($size); + $file_info = new Class_File_Info($path); + return $file_info->fileNameWithExtension().', '.$this->view->memoryFormat($file_info->fileSize()); } } ?> \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/RechercheControllerAlbumAudioRecordTest.php b/tests/application/modules/opac/controllers/RechercheControllerAlbumAudioRecordTest.php index 69f81d8be0080db859301417c809f895e6d7f907..7f2372aaa094ec89fe99f6634e0ab9443a85d6b7 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerAlbumAudioRecordTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerAlbumAudioRecordTest.php @@ -133,7 +133,7 @@ class RechercheControllerAlbumAudioRecordViewNoticeTest extends RechercheControl /** @test */ public function noticeUnknownMorceauTitleShouldBeUnknown() { - $this->assertEquals('unknown', + $this->assertEquals('Unknown', $this->_notice->getMorceaux()['morceaux'][1][3]['titre']); } @@ -231,6 +231,7 @@ class RechercheControllerAlbumAudioRecordViewDetailsTest extends RechercheContro + class RechercheControllerAlbumAudioRecordViewRessourcesNumeriquesTest extends RechercheControllerAlbumAudioRecordTestCase { public function setUp() { parent::setUp(); @@ -251,8 +252,15 @@ class RechercheControllerAlbumAudioRecordViewRessourcesNumeriquesTest extends Re /** @test **/ - public function liShouldBeFileNameUnknown() { - $this->assertXPathContentContains('//ol//li', 'unknown.mp3'); + public function liForUnknownShouldBeFileNameUnknownMp3ZeroBite() { + $this->assertXPathContentContains('//ol//li', 'Unknown'); + $this->assertXPathContentContains('//ol//li', '[mp3, 0 o]'); + } + + + /** @test **/ + public function liShouldContainsFilenameNameTheProphecy() { + $this->assertXPathContentContains('//ol//li', 'The prophecy'); } @@ -306,8 +314,14 @@ class RechercheControllerAlbumAudioRecordAsTelephoneViewRessourcesNumeriquesTest /** @test **/ - public function liShouldBeFileNameUnknown() { - $this->assertXPathContentContains('//ol//li', 'unknown.mp3'); + public function liShouldContainsFileNameUnknown() { + $this->assertXPathContentContains('//ol//li', 'Unknown'); + } + + + /** @test **/ + public function liShouldContainsFilenameNameTheProphecy() { + $this->assertXPathContentContains('//ol//li', 'The prophecy'); } } ?> \ No newline at end of file diff --git a/tests/library/Class/File/InfoTest.php b/tests/library/Class/File/InfoTest.php index eab7f9562f6717aeb02accf8e118bb2469ca2738..0fad936353993bbc7e3f52cf0df259becf1a2c3f 100644 --- a/tests/library/Class/File/InfoTest.php +++ b/tests/library/Class/File/InfoTest.php @@ -22,13 +22,13 @@ class FileInfoTest extends PHPUnit_Framework_TestCase { public function fixtures() { return [ - ['one.mp3', 'one' ], - ['one', 'one'], + ['one.mp3', 'One' ], + ['one', 'One'], ['.mp3', ''], ['', ''], [null, ''], - ['dark_vador-the*vilain', 'dark vador the vilain'], - ['666 beast 111', 'beast'] + ['dark_vador-the*vilain', 'Dark vador the vilain'], + ['666 beast 111', 'Beast'] ]; }