1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-11 23:54:06 +02:00

feat(media): we should have media instead of uploads folder Media API #515

This commit is contained in:
Awilum
2020-12-17 20:27:49 +03:00
parent 01a9872884
commit d5c3fc75a1
11 changed files with 55 additions and 55 deletions

View File

@@ -5,23 +5,23 @@ use Flextype\Component\Filesystem\Filesystem;
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/entries')->create();
filesystem()->directory(PATH['project'] . '/uploads')->create(0755, true);
filesystem()->directory(PATH['project'] . '/uploads/.meta')->create(0755, true);
filesystem()->directory(PATH['project'] . '/uploads/foo')->create(0755, true);
filesystem()->directory(PATH['project'] . '/uploads/.meta/foo')->create(0755, true);
filesystem()->directory(PATH['project'] . '/media/.meta')->create(0755, true);
filesystem()->directory(PATH['project'] . '/media/foo')->create(0755, true);
filesystem()->directory(PATH['project'] . '/media/.meta/foo')->create(0755, true);
});
afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/uploads/.meta')->delete();
filesystem()->directory(PATH['project'] . '/media/.meta')->delete();
filesystem()->directory(PATH['project'] . '/uploads')->delete();
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('test media_files field', function () {
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/uploads/bar.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/bar.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Bar', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/media/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/media/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/media/bar.txt')->put('foo');
filesystem()->file(PATH['project'] . '/media/.meta/bar.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Bar', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
flextype('entries')->create('media', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/media/entry.md')->get()));

View File

@@ -4,41 +4,41 @@ declare(strict_types=1);
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/uploads')->create(0755, true);
filesystem()->directory(PATH['project'] . '/uploads/.meta')->create(0755, true);
filesystem()->directory(PATH['project'] . '/media/.meta')->create(0755, true);
});
afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/uploads/.meta')->delete();
filesystem()->directory(PATH['project'] . '/media/.meta')->delete();
filesystem()->directory(PATH['project'] . '/uploads')->delete();
});
test('test update() method', function () {
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/media/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/media/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertTrue(flextype('media_files_meta')->update('foo.txt', 'description', 'Foo description'));
$this->assertEquals('Foo description', flextype('yaml')->decode(filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->get())['description']);
$this->assertEquals('Foo description', flextype('yaml')->decode(filesystem()->file(PATH['project'] . '/media/.meta/foo.txt.yaml')->get())['description']);
});
test('test add() method', function () {
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/media/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/media/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertTrue(flextype('media_files_meta')->add('foo.txt', 'bar', 'Bar'));
$this->assertEquals('Bar', flextype('yaml')->decode(filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->get())['bar']);
$this->assertEquals('Bar', flextype('yaml')->decode(filesystem()->file(PATH['project'] . '/media/.meta/foo.txt.yaml')->get())['bar']);
});
test('test delete() method', function () {
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/media/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/media/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertTrue(flextype('media_files_meta')->delete('foo.txt', 'title'));
$this->assertTrue(empty(flextype('yaml')->decode(filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->get())['bar']));
$this->assertTrue(empty(flextype('yaml')->decode(filesystem()->file(PATH['project'] . '/media/.meta/foo.txt.yaml')->get())['bar']));
});
test('test getFileMetaLocation() method', function () {
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/media/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/media/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertStringContainsString('foo.txt.yaml',
flextype('media_files_meta')->getFileMetaLocation('foo.txt'));
});

View File

@@ -4,19 +4,19 @@ declare(strict_types=1);
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/uploads')->create(0755, true);
filesystem()->directory(PATH['project'] . '/uploads/.meta')->create(0755, true);
filesystem()->directory(PATH['project'] . '/media/.meta')->create(0755, true);
});
afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/uploads/.meta')->delete();
filesystem()->directory(PATH['project'] . '/media/.meta')->delete();
filesystem()->directory(PATH['project'] . '/uploads')->delete();
});
test('test fetch() method', function () {
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/uploads/bar.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/bar.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Bar', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/media/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/media/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/media/bar.txt')->put('foo');
filesystem()->file(PATH['project'] . '/media/.meta/bar.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Bar', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertTrue(count(flextype('media_files')->fetch('foo.txt')) > 0);
$this->assertEquals('Foo', flextype('media_files')->fetch('foo.txt')['title']);
@@ -26,8 +26,8 @@ test('test fetch() method', function () {
});
test('test move() method', function () {
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/media/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/media/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertTrue(flextype('media_files')->move('foo.txt', 'bar.txt'));
$this->assertTrue(flextype('media_files')->move('bar.txt', 'foo.txt'));
@@ -38,8 +38,8 @@ test('test copy() method', function () {
$this->assertTrue(flextype('media_folders')->create('foo'));
$this->assertTrue(flextype('media_folders')->create('bar'));
filesystem()->file(PATH['project'] . '/uploads/foo/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/media/foo/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/media/.meta/foo/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertTrue(flextype('media_files')->copy('foo/foo.txt', 'bar/foo.txt'));
$this->assertTrue(flextype('media_files')->copy('foo/foo.txt', 'bar/bar.txt'));
@@ -47,22 +47,22 @@ test('test copy() method', function () {
});
test('test has() method', function () {
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/media/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/media/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertTrue(flextype('media_files')->has('foo.txt'));
$this->assertFalse(flextype('media_files')->has('bar.txt'));
});
test('test getFileLocation() method', function () {
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/media/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/media/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertStringContainsString('foo.txt', flextype('media_files')->getFileLocation('foo.txt'));
});
test('test delete() method', function () {
filesystem()->file(PATH['project'] . '/uploads/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/uploads/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
filesystem()->file(PATH['project'] . '/media/foo.txt')->put('foo');
filesystem()->file(PATH['project'] . '/media/.meta/foo.txt.yaml')->put(flextype('yaml')->encode(['title' => 'Foo', 'description' => '', 'type' => 'text/plain', 'filesize' => 3, 'uploaded_on' => 1603090370, 'exif' => []]));
$this->assertTrue(flextype('media_files')->delete('foo.txt'));
$this->assertFalse(flextype('media_files')->delete('foo.txt'));
});

View File

@@ -4,11 +4,11 @@ declare(strict_types=1);
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/uploads')->create(0755, true);
filesystem()->directory(PATH['project'] . '/uploads/.meta')->create(0755, true);
filesystem()->directory(PATH['project'] . '/media/.meta')->create(0755, true);
});
afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/uploads/.meta')->delete();
filesystem()->directory(PATH['project'] . '/media/.meta')->delete();
filesystem()->directory(PATH['project'] . '/uploads')->delete();
});

View File

@@ -4,11 +4,11 @@ declare(strict_types=1);
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/uploads')->create(0755, true);
filesystem()->directory(PATH['project'] . '/uploads/.meta')->create(0755, true);
filesystem()->directory(PATH['project'] . '/media/.meta')->create(0755, true);
});
afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/uploads/.meta')->delete();
filesystem()->directory(PATH['project'] . '/media/.meta')->delete();
filesystem()->directory(PATH['project'] . '/uploads')->delete();
});