Classi per la configurazione upload
Cristiano Magro
2019-07-09 898526eeb23b1a10e852c666242149f44b673fcb
Refactor creazione nuovo filtro o aggiunta estensione a filtro precedente
2 files modified
37 ■■■■ changed files
src/Vola/UploadFile/FilesFilter.class.php 26 ●●●● patch | view | raw | blame | history
tests/Vola/UploadFile/FilesFilterTest.php 11 ●●●● patch | view | raw | blame | history
src/Vola/UploadFile/FilesFilter.class.php
@@ -24,15 +24,12 @@
    public function addExt($extension = '')
    {
        if ($extension != '') {
            $titolo = $this->decodeTitolo($extension);
            if ($titolo != null) {
                if($this->filtro[$titolo] instanceof FilterExt){
                    $this->filtro[$titolo]->addExt($extension);
                $this->addExtensionToFilter($titolo, $extension);
                } else {
                    $filtro = new FilterExt($titolo, $extension);
                    $this->filtro[$titolo] = $filtro;
                }
                $this->createFilter($titolo, $extension);
            }
        }
        return $this;
@@ -59,4 +56,23 @@
        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);
    }
}
tests/Vola/UploadFile/FilesFilterTest.php
@@ -13,7 +13,8 @@
     * Set up fixture, inizializzazione dei test.
     * Eseguito prima di ogni test
     */
    protected function setUp() {
    protected function setUp()
    {
        $this->object = new FilesFilter();
    }
@@ -21,7 +22,8 @@
     * 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()
    {
    }
@@ -41,7 +43,8 @@
    }
    public function addExtension(){
    public function addExtension()
    {
        return [
          [[], '[]'],
          [['fasullo'], '[]'],
@@ -50,6 +53,8 @@
          [['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"}]'],
        ];
    }