Initial commit IQParts\Content
This commit is contained in:
64
test/Unit/FileTest.php
Normal file
64
test/Unit/FileTest.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace IQParts\ContentTest\Unit;
|
||||
|
||||
use IQParts\Content\Object\File;
|
||||
use IQParts\ContentTest\AbstractTestCase;
|
||||
use League\Flysystem\Adapter\Local;
|
||||
use League\Flysystem\File as FlyFile;
|
||||
use League\Flysystem\Filesystem;
|
||||
|
||||
/**
|
||||
* Class FileTest
|
||||
* @package IQParts\ContentTest\Unit
|
||||
*/
|
||||
final class FileTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @return File
|
||||
*/
|
||||
private function createFile(bool $extension = true): File
|
||||
{
|
||||
$fs = new Filesystem(new Local(__DIR__ . '/../files'));
|
||||
|
||||
if ($extension) {
|
||||
return new File($fs->get('test.txt'));
|
||||
} else {
|
||||
return new File($fs->get('folder/folder/no-extension'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testFile()
|
||||
{
|
||||
$file = $this->createFile(true);
|
||||
|
||||
$this->assertEquals('txt', $file->getExtension());
|
||||
$this->assertEquals('test.txt', $file->getBasename());
|
||||
$this->assertEquals(base64_encode('/'), $file->getParent());
|
||||
$this->assertTrue(is_int($file->getSize()));
|
||||
$this->assertEquals(md5(file_get_contents(__DIR__ . '/../files/test.txt')), $file->getMD5());
|
||||
$this->assertTrue($file->isEditable());
|
||||
$this->assertEquals('', $file->getContents());;
|
||||
$this->assertTrue(is_integer($file->getTimestamp()));
|
||||
$this->assertInstanceOf(\DateTime::class, $file->getDate());
|
||||
$this->assertEquals('text/plain', $file->getMimetype());
|
||||
$this->assertInstanceOf(FlyFile::class, $file->getFile());
|
||||
$this->assertEquals(base64_encode('test.txt'), $file->getId());
|
||||
$this->assertTrue($file->isFile());
|
||||
$this->assertEquals('test.txt', $file->getPath());
|
||||
$this->assertTrue(is_resource($file->getStream()));
|
||||
$this->assertTrue(is_array($file->toArray()));
|
||||
$this->assertFalse($file->isDir());
|
||||
|
||||
$file = $this->createFile(false);
|
||||
$this->assertEquals('', $file->getExtension());
|
||||
$this->assertInstanceOf(File::class, File::fromVariables(
|
||||
'folder/folder/no-extension',
|
||||
'folder/folder',
|
||||
time()
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user