Skip to content
Snippets Groups Projects
Commit 64d2f529 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

Skin object take care of available skins list

parent 38a278cf
Branches
Tags
2 merge requests!258Dev/13872 Orphee Allow Hold Available Items,!7Multiple Skin Dirs
......@@ -924,17 +924,8 @@ class Class_Profil extends Storm_Model_Abstract {
/**
* @return array
*/
function getAvailableSkins() {
// Parcourir le dossier des skins opac
$scanlisting = scandir('./public/opac/skins');
$availableSkins = array();
foreach($scanlisting as $key => $value)
if (is_dir('./public/opac/skins/' . $value) and $value[0] != '.')
$availableSkins[$value] = $value;
return $availableSkins;
public function getAvailableSkins() {
return $this->_getSkin()->getAvailables();
}
......
......@@ -82,6 +82,28 @@ class Class_Profil_Skin {
}
public function getAvailables() {
$skins = [];
foreach (['.' . self::DEFAULT_PATH] as $path)
$skins = array_merge($skins, $this->getAvailablesIn($path));
return $skins;
}
protected function getAvailablesIn($path) {
$file_system = $this->getFileSystem();
if (false === ($dirs = @$file_system->scandir($path)))
return [];
$skins = [];
foreach ($dirs as $dir)
if ($file_system->is_dir($path . $dir) and $dir[0] != '.')
$skins[$dir] = $dir;
return $skins;
}
/** @category testing */
public static function setFileSystem($file_system) {
self::$_file_system = $file_system;
......
......@@ -22,7 +22,7 @@
class Class_Testing_FileSystem {
protected $_known_functions = ['rmdir', 'unlink', 'fopen', 'fseek', 'fgets',
'filesize', 'fclose', 'ftell', 'fread', 'feof',
'getcwd', 'file_exists'];
'getcwd', 'file_exists', 'scandir', 'is_dir'];
public function __call($name, $args) {
if (!in_array($name, $this->_known_functions))
......
......@@ -47,7 +47,12 @@ class Class_Profil_SkinExistTest extends Class_Profil_SkinTestCase {
parent::setUp();
$this->_file_system
->whenCalled('file_exists')
->answers(true);
->answers(true)
->whenCalled('scandir')
->answers(['.', '..', 'afi', 'original', 'testing'])
->whenCalled('is_dir')->answers(true);
}
......@@ -94,6 +99,15 @@ class Class_Profil_SkinExistTest extends Class_Profil_SkinTestCase {
public function templatesPathShouldContainsTesting() {
$this->assertContains('testing/templates', $this->_skin->getTemplatesPath());
}
/** @test */
public function availableShouldBeAsExpected() {
$this->assertEquals(['afi' => 'afi',
'original' => 'original',
'testing' => 'testing'],
$this->_skin->getAvailables());
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment