Refactor creazione nuovo filtro o aggiunta estensione a filtro precedente
| | |
| | | public function toJson() |
| | | { |
| | | |
| | | $temp = array (); |
| | | $temp = array(); |
| | | |
| | | /** @var FilterExt $filtro */ |
| | | foreach ($this->filtro as $filtro){ |
| | | foreach ($this->filtro as $filtro) { |
| | | $temp[] = $filtro->getFilterObj(); |
| | | } |
| | | |
| | |
| | | |
| | | public function addExt($extension = '') |
| | | { |
| | | if ($extension != '') { |
| | | $titolo = $this->decodeTitolo($extension); |
| | | if ($titolo != null) { |
| | | if($this->filtro[$titolo] instanceof FilterExt){ |
| | | $this->filtro[$titolo]->addExt($extension); |
| | | } else { |
| | | $filtro = new FilterExt($titolo, $extension); |
| | | $this->filtro[$titolo] = $filtro; |
| | | } |
| | | $titolo = $this->decodeTitolo($extension); |
| | | if ($titolo != null) { |
| | | if ($this->filtro[$titolo] instanceof FilterExt) { |
| | | $this->addExtensionToFilter($titolo, $extension); |
| | | } else { |
| | | $this->createFilter($titolo, $extension); |
| | | } |
| | | } |
| | | return $this; |
| | |
| | | return $titolo; |
| | | } |
| | | |
| | | /** |
| | | * @param $titolo |
| | | * @param $extension |
| | | */ |
| | | private function createFilter($titolo, $extension) |
| | | { |
| | | $filtro = new FilterExt($titolo, $extension); |
| | | $this->filtro[$titolo] = $filtro; |
| | | } |
| | | |
| | | /** |
| | | * @param $titolo |
| | | * @param $extension |
| | | */ |
| | | private function addExtensionToFilter($titolo, $extension) |
| | | { |
| | | $this->filtro[$titolo]->addExt($extension); |
| | | } |
| | | |
| | | } |
| | |
| | | * Set up fixture, inizializzazione dei test. |
| | | * Eseguito prima di ogni test |
| | | */ |
| | | protected function setUp() { |
| | | protected function setUp() |
| | | { |
| | | $this->object = new FilesFilter(); |
| | | } |
| | | |
| | |
| | | * Tears down the fixture, for example, closes a network connection. |
| | | * This method is called after a test is executed. |
| | | */ |
| | | protected function tearDown() { |
| | | protected function tearDown() |
| | | { |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | public function addExtension(){ |
| | | public function addExtension() |
| | | { |
| | | return [ |
| | | [[], '[]'], |
| | | [['fasullo'], '[]'], |
| | | [['gif'], '[{"title":"Image files","extensions":"gif"}]'], |
| | | [['doc'], '[{"title":"Documenti","extensions":"doc"}]'], |
| | | [['DOC'], '[{"title":"Documenti","extensions":"DOC"}]'], |
| | | [['txt'], '[{"title":"Documenti","extensions":"txt"}]'], |
| | | [['DOc', 'gif'],'[{"title":"Documenti","extensions":"DOc"},{"title":"Image files","extensions":"gif"}]'], |
| | | [[], '[]'], |
| | | [['fasullo'], '[]'], |
| | | [['gif'], '[{"title":"Image files","extensions":"gif"}]'], |
| | | [['doc'], '[{"title":"Documenti","extensions":"doc"}]'], |
| | | [['DOC'], '[{"title":"Documenti","extensions":"DOC"}]'], |
| | | [['txt'], '[{"title":"Documenti","extensions":"txt"}]'], |
| | | [['DOc', 'gif'], '[{"title":"Documenti","extensions":"DOc"},{"title":"Image files","extensions":"gif"}]'], |
| | | [['txt', 'doc'], '[{"title":"Documenti","extensions":"doc,txt"}]'], |
| | | [['gif', 'fasullo'], '[{"title":"Image files","extensions":"gif"}]'], |
| | | ]; |
| | | } |
| | | |