Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Wagner committed Feb 14, 2018
1 parent 522e801 commit 2cc28ab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/File/FileUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,18 +287,16 @@ public function getFolderFromDca($folder, DataContainer $dc = null)
} elseif (is_callable($folder) && null !== $dc) {
$method = $folder;
$folder = $method($dc);
} else {
} elseif (is_string($folder)) {
if (false !== strpos($folder, '../')) {
throw new \Exception("Invalid target path $folder");
}
}

if ($folder instanceof File) {
$folder = $folder->value;
} else {
if ($folder instanceof FilesModel) {
$folder = $folder->path;
}
} elseif ($folder instanceof FilesModel) {
$folder = $folder->path;
}

if (Validator::isUuid($folder)) {
Expand Down
21 changes: 21 additions & 0 deletions tests/File/FileUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,25 @@ public function testGetFileLineCount()
$lines = $fileUtil->getFileLineCount('foo');
$this->assertSame('fopen(/foo): failed to open stream: No such file or directory', $lines);
}

public function testGetFolderFromDca()
{
$framework = $this->mockContaoFramework();
$fileUtil = new FileUtil($framework);
$folder = $fileUtil->getFolderFromDca($this->getTempDir().'/files');
$this->assertSame($this->getTempDir().'/files', $folder);

$folder = $fileUtil->getFolderFromDca('3712c116-1193-11e8-b642-0ed5f89f718b');
$this->assertSame($this->getTempDir().'/files', $folder);

$file = new File($this->getTempDir().'/files/dcaFile');
$folder = $fileUtil->getFolderFromDca($file);
$this->assertSame($this->getTempDir().'/files/dcaFile', $folder);

try {
$fileUtil->getFolderFromDca('dlfjn../ds');
} catch (\Exception $exception) {
$this->assertSame('Invalid target path dlfjn../ds', $exception->getMessage());
}
}
}

0 comments on commit 2cc28ab

Please sign in to comment.