diff --git a/Tests/Entity/UploadedFileTest.php b/Tests/Entity/UploadedFileTest.php new file mode 100644 index 0000000000000000000000000000000000000000..5327921bac18b01f39389b947674e7c85598b325 --- /dev/null +++ b/Tests/Entity/UploadedFileTest.php @@ -0,0 +1,58 @@ +<?php + +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 + */ + public function testIsSafePath($isSafe, $path) + { + $this->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/'); + + $this->assertEquals('machin/chose/muche', $this->file->getPath()); + } +}