<?php declare(strict_types=1);
/*
 * Copyright (C) 2015-2017 IRSTEA
 * All rights reserved.
 */

namespace Irstea\FileUploadBundle\Tests\Entity;

use Irstea\FileUploadBundle\Entity\UploadedFile;
use PHPUnit_Framework_TestCase;

/**
 * Generated by PHPUnit_SkeletonGenerator on 2015-01-26 at 10:27:46.
 */
class UploadedFileTest extends PHPUnit_Framework_TestCase
{
    /**
     * @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()
    {
        $this->file = new UploadedFile();
    }

    /**
     * @covers       \Irstea\FileUploadBundle\Entity\UploadedFile::isSafePath
     * @dataProvider getIsSafePathvalues
     *
     * @param mixed $isSafe
     * @param mixed $path
     */
    public function testIsSafePath($isSafe, $path)
    {
        static::assertEquals($isSafe, UploadedFile::isSafePath($path));
    }

    public function getIsSafePathvalues()
    {
        return [
            [true, 'toto.php'],
            [false, '../toto.php'],
            [true, 'bla/../toto.php'],
            [false, 'bla/.././../toto.php'],
            [false, '/../toto.php'],
            [true, '/bla/../toto.php'],
            [false, '../toto.php'],
        ];
    }

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

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

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