Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Wagner committed Feb 14, 2018
1 parent da548b5 commit 522e801
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
23 changes: 18 additions & 5 deletions tests/File/FileUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function setUp()
parent::setUp();

if (!defined('TL_ROOT')) {
\define('TL_ROOT', __DIR__);
\define('TL_ROOT', '');
}

$fs = new Filesystem();
Expand Down Expand Up @@ -97,9 +97,22 @@ public function testGetUniqueFileNameWithinTarget()
{
$framework = $this->mockContaoFramework();
$fileUtil = new FileUtil($framework);
$fileName = $fileUtil->getUniqueFileNameWithinTarget($this->getTempDir().'/files/testfile.txt');

$fileName = $fileUtil->getUniqueFileNameWithinTarget($this->getTempDir().'/files/test');
$this->assertSame(ltrim($this->getTempDir().'/files/test', '/'), $fileName);

$fileName = $fileUtil->getUniqueFileNameWithinTarget($this->getTempDir().'/files/test', 'te');
$this->assertSame(ltrim($this->getTempDir().'/files/_1.', '/'), $fileName);

$fileName = $fileUtil->getUniqueFileNameWithinTarget($this->getTempDir().'/test/test/test');
$this->assertFalse($fileName);

file_put_contents($this->getTempDir().'/files/test', 'test');
$fileName = $fileUtil->getUniqueFileNameWithinTarget($this->getTempDir().'/files/test');
$this->assertSame(ltrim($this->getTempDir().'/files/test_1.', '/'), $fileName);

$fileName = $fileUtil->getUniqueFileNameWithinTarget($this->getTempDir().'/files/test', null, 100);
$this->assertNotSame(ltrim($this->getTempDir().'/files/test', '/'), $fileName);
}

public function testFormatSizeUnits()
Expand Down Expand Up @@ -195,7 +208,7 @@ public function testGetFilesFromUuid()
$file = $fileUtil->getFileFromUuid('uuid');
$this->assertNull($file);

file_put_contents(TL_ROOT.'/'.$this->getTempDir().'/files/testFile', 'test');
file_put_contents($this->getTempDir().'/files/testFile', 'test');
$container = System::getContainer();
$filesModel = $this->mockClassWithProperties(FilesModel::class, ['path' => $this->getTempDir().'/files/testFile']);
$filesAdapter = $this->mockAdapter(['findByUuid']);
Expand Down Expand Up @@ -248,7 +261,7 @@ public function testGetFolderFromUuid()

public function testGetFileLineCount()
{
file_put_contents(TL_ROOT.'/'.$this->getTempDir().'/files/testFile', 'test');
file_put_contents($this->getTempDir().'/files/testFile', 'test');

$framework = $this->mockContaoFramework();
$fileUtil = new FileUtil($framework);
Expand All @@ -257,6 +270,6 @@ public function testGetFileLineCount()
$this->assertSame(1, $lines);

$lines = $fileUtil->getFileLineCount('foo');
$this->assertSame('fopen(/home/kwagner/Kunden/github/contao-utils-bundle/tests/File/foo): failed to open stream: No such file or directory', $lines);
$this->assertSame('fopen(/foo): failed to open stream: No such file or directory', $lines);
}
}
1 change: 0 additions & 1 deletion tests/File/tmp/FileUtilTest_5a842f2434aa4/files/testFile

This file was deleted.

0 comments on commit 522e801

Please sign in to comment.