HelperFileTest.php 3.9 KB
Newer Older
Carsten  Rose's avatar
Carsten Rose committed
1
2
3
4
5
6
7
8
<?php
/**
 * Created by PhpStorm.
 * User: crose
 * Date: 11/02/18
 * Time: 9:16 PM
 */

Marc Egger's avatar
Marc Egger committed
9
namespace IMATHUZH\Qfq\Tests\Unit\Core\Helper;
Carsten  Rose's avatar
Carsten Rose committed
10

Marc Egger's avatar
Marc Egger committed
11
12
 
use IMATHUZH\Qfq\Core\Helper\HelperFile;
13
use IMATHUZH\Qfq\Core\Helper\Path;
Carsten  Rose's avatar
Carsten Rose committed
14
15
16
17
18
19
20
21
22
23
use PHPUnit\Framework\TestCase;


/**
 * Class HelperFileTest
 * @package qfq
 */
class HelperFileTest extends TestCase {

    /**
Marc Egger's avatar
Marc Egger committed
24
     * @throws \UserFormException
Carsten  Rose's avatar
Carsten Rose committed
25
26
27
28
29
30
31
     */
    public function testGetFileTypeHighlight() {

        $this->assertEquals('', HelperFile::getFileTypeHighlight('',''));
        $this->assertEquals('', HelperFile::getFileTypeHighlight('','fileadmin/test.js'));

        $this->assertEquals('', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_OFF,''));
Carsten  Rose's avatar
Carsten Rose committed
32
33
        $this->assertEquals('' , HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_OFF,'fileadmin/test.js'));

Carsten  Rose's avatar
Carsten Rose committed
34
        $this->assertEquals('', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO,''));
Carsten  Rose's avatar
Carsten Rose committed
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
        $this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/javascript.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_JAVASCRIPT,''));
        $this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.qfq.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_QFQ,''));
        $this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.py.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_PYTHON,''));
        $this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.m.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_MATLAB,''));

        $this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/javascript.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_JAVASCRIPT,'fileadmin/test.js'));
        $this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.qfq.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_QFQ, 'fileadmin/test.js'));
        $this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.py.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_PYTHON, 'fileadmin/test.js'));
        $this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.m.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_MATLAB, 'fileadmin/test.js'));

        $this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/javascript.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO, 'fileadmin/test.js'));
        $this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.php.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO, 'fileadmin/test.php'));
        $this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.qfq.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO, 'fileadmin/test.qfq'));
        $this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.py.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO, 'fileadmin/test.py'));
        $this->assertEquals(Path::urlExt(Path::EXT_TO_HIGHLIGHT_JSON) . '/highlight.m.json', HelperFile::getFileTypeHighlight(FE_HIGHLIGHT_AUTO, 'fileadmin/test.m'));
Carsten  Rose's avatar
Carsten Rose committed
51
    }
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

    public function testJoinPathFilename() {

        $this->assertEquals('', HelperFile::joinPathFilename('', ''));
        $this->assertEquals('/', HelperFile::joinPathFilename('/', ''));
        $this->assertEquals('/', HelperFile::joinPathFilename('', '/'));
        $this->assertEquals('/', HelperFile::joinPathFilename('/', '/'));

        $this->assertEquals('a/b', HelperFile::joinPathFilename('a', 'b'));
        $this->assertEquals('/a/b', HelperFile::joinPathFilename('/a', 'b'));
        $this->assertEquals('/b', HelperFile::joinPathFilename('a', '/b'));
        $this->assertEquals('/b', HelperFile::joinPathFilename('/a', '/b'));

        $this->assertEquals('a/b', HelperFile::joinPathFilename('a/', 'b'));
        $this->assertEquals('a/b', HelperFile::joinPathFilename('a', 'b'));
        $this->assertEquals('/b', HelperFile::joinPathFilename('a/', '/b'));
        $this->assertEquals('/b', HelperFile::joinPathFilename('a', '/b'));
    }

Carsten  Rose's avatar
Carsten Rose committed
71
72
}