UploadedFileTest.php 1.5 KB
Newer Older
Guillaume Perréal's avatar
Guillaume Perréal committed
1
<?php declare(strict_types=1);
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
2
/*
3
 * Copyright (C) 2015-2018 IRSTEA
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
4
5
 * All rights reserved.
 */
6
7
8
9

namespace Irstea\FileUploadBundle\Tests\Entity;

use Irstea\FileUploadBundle\Entity\UploadedFile;
10
use PHPUnit\Framework\TestCase;
11
12
13
14

/**
 * Generated by PHPUnit_SkeletonGenerator on 2015-01-26 at 10:27:46.
 */
15
class UploadedFileTest extends TestCase
16
17
18
19
20
21
22
23
24
25
26
27
{
    /**
     * @var UploadedFile
     */
    protected $file;

    /**
     * Sets up the fixture, for example, opens a network connection.
     * This method is called before a test is executed.
     */
    protected function setUp()
    {
Raidelet Nicolas's avatar
CS    
Raidelet Nicolas committed
28
        $this->file = new UploadedFile();
29
30
31
    }

    /**
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
32
     * @covers       \Irstea\FileUploadBundle\Entity\UploadedFile::isSafePath
33
     * @dataProvider getIsSafePathvalues
Guillaume Perréal's avatar
CS.    
Guillaume Perréal committed
34
35
36
     *
     * @param mixed $isSafe
     * @param mixed $path
37
38
39
     */
    public function testIsSafePath($isSafe, $path)
    {
40
        static::assertEquals($isSafe, UploadedFile::isSafePath($path));
41
42
43
44
45
    }

    public function getIsSafePathvalues()
    {
        return [
Raidelet Nicolas's avatar
CS    
Raidelet Nicolas committed
46
            [true, 'toto.php'],
47
            [false, '../toto.php'],
Raidelet Nicolas's avatar
CS    
Raidelet Nicolas committed
48
            [true, 'bla/../toto.php'],
49
50
            [false, 'bla/.././../toto.php'],
            [false, '/../toto.php'],
Raidelet Nicolas's avatar
CS    
Raidelet Nicolas committed
51
52
            [true, '/bla/../toto.php'],
            [false, '../toto.php'],
53
54
55
56
57
58
59
60
61
        ];
    }

    public function testMoveTo()
    {
        $this->file->setPath('truc/muche');

        $this->file->moveTo('machin/chose/');

62
        static::assertEquals('machin/chose/muche', $this->file->getPath());
63
64
    }
}