From a7d94be9e70c71df85f7d2fe47087451c9bd2dd4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Guillaume=20Perr=C3=A9al?= <guillaume.perreal@irstea.fr>
Date: Mon, 26 Jan 2015 15:05:25 +0100
Subject: [PATCH] Ajout de tests pour UploadedFile.

---
 Tests/Entity/UploadedFileTest.php | 58 +++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
 create mode 100644 Tests/Entity/UploadedFileTest.php

diff --git a/Tests/Entity/UploadedFileTest.php b/Tests/Entity/UploadedFileTest.php
new file mode 100644
index 00000000..5327921b
--- /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());
+    }
+}
-- 
GitLab