mirror of
https://github.com/flextype/flextype.git
synced 2025-08-12 08:04:05 +02:00
feat(media): standardise media container names for Media API #517
This commit is contained in:
@@ -19,17 +19,17 @@ afterEach(function (): void {
|
||||
test('test media.files field', function () {
|
||||
|
||||
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/.meta/foo.txt.yaml')->put(flextype('serializers')->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' => []]));
|
||||
filesystem()->file(PATH['project'] . '/media/.meta/bar.txt.yaml')->put(flextype('serializers')->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()));
|
||||
flextype('entries')->create('media', flextype('serializers')->frontmatter()->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/media/entry.md')->get()));
|
||||
|
||||
flextype('media.files')::macro('fetchExtraData', function ($id, $options) {
|
||||
flextype('media')->files()::macro('fetchExtraData', function ($id, $options) {
|
||||
return ['id' => $id, 'options' => $options];
|
||||
});
|
||||
|
||||
flextype('media.folders')::macro('fetchExtraData', function ($id, $options) {
|
||||
flextype('media')->folders()::macro('fetchExtraData', function ($id, $options) {
|
||||
return ['id' => $id, 'options' => $options];
|
||||
});
|
||||
|
||||
|
@@ -14,31 +14,31 @@ afterEach(function (): void {
|
||||
|
||||
test('test update() method', function () {
|
||||
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/.meta/foo.txt.yaml')->put(flextype('serializers')->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'] . '/media/.meta/foo.txt.yaml')->get())['description']);
|
||||
$this->assertTrue(flextype('media')->files()->meta()->update('foo.txt', 'description', 'Foo description'));
|
||||
$this->assertEquals('Foo description', flextype('serializers')->yaml()->decode(filesystem()->file(PATH['project'] . '/media/.meta/foo.txt.yaml')->get())['description']);
|
||||
});
|
||||
|
||||
test('test add() method', function () {
|
||||
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/.meta/foo.txt.yaml')->put(flextype('serializers')->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'] . '/media/.meta/foo.txt.yaml')->get())['bar']);
|
||||
$this->assertTrue(flextype('media')->files()->meta()->add('foo.txt', 'bar', 'Bar'));
|
||||
$this->assertEquals('Bar', flextype('serializers')->yaml()->decode(filesystem()->file(PATH['project'] . '/media/.meta/foo.txt.yaml')->get())['bar']);
|
||||
});
|
||||
|
||||
test('test delete() method', function () {
|
||||
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/.meta/foo.txt.yaml')->put(flextype('serializers')->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'] . '/media/.meta/foo.txt.yaml')->get())['bar']));
|
||||
$this->assertTrue(flextype('media')->files()->meta()->delete('foo.txt', 'title'));
|
||||
$this->assertTrue(empty(flextype('serializers')->yaml()->decode(filesystem()->file(PATH['project'] . '/media/.meta/foo.txt.yaml')->get())['bar']));
|
||||
});
|
||||
|
||||
test('test getFileMetaLocation() method', function () {
|
||||
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/.meta/foo.txt.yaml')->put(flextype('serializers')->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'));
|
||||
flextype('media')->files()->meta()->getFileMetaLocation('foo.txt'));
|
||||
});
|
||||
|
@@ -14,55 +14,55 @@ afterEach(function (): void {
|
||||
|
||||
test('test fetch() method', function () {
|
||||
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/.meta/foo.txt.yaml')->put(flextype('serializers')->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' => []]));
|
||||
filesystem()->file(PATH['project'] . '/media/.meta/bar.txt.yaml')->put(flextype('serializers')->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']);
|
||||
$this->assertTrue(count(flextype('media')->files()->fetch('foo.txt')) > 0);
|
||||
$this->assertEquals('Foo', flextype('media')->files()->fetch('foo.txt')['title']);
|
||||
|
||||
$this->assertTrue(count(flextype('media.files')->fetch('/', ['collection' => true])) == 2);
|
||||
$this->assertEquals('Foo', flextype('media.files')->fetch('/', ['collection' => true])['foo.txt']['title']);
|
||||
$this->assertTrue(count(flextype('media')->files()->fetch('/', ['collection' => true])) == 2);
|
||||
$this->assertEquals('Foo', flextype('media')->files()->fetch('/', ['collection' => true])['foo.txt']['title']);
|
||||
});
|
||||
|
||||
test('test move() method', function () {
|
||||
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/.meta/foo.txt.yaml')->put(flextype('serializers')->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'));
|
||||
$this->assertFalse(flextype('media.files')->move('bar.txt', 'foo.txt'));
|
||||
$this->assertTrue(flextype('media')->files()->move('foo.txt', 'bar.txt'));
|
||||
$this->assertTrue(flextype('media')->files()->move('bar.txt', 'foo.txt'));
|
||||
$this->assertFalse(flextype('media')->files()->move('bar.txt', 'foo.txt'));
|
||||
});
|
||||
|
||||
test('test copy() method', function () {
|
||||
$this->assertTrue(flextype('media.folders')->create('foo'));
|
||||
$this->assertTrue(flextype('media.folders')->create('bar'));
|
||||
$this->assertTrue(flextype('media')->folders()->create('foo'));
|
||||
$this->assertTrue(flextype('media')->folders()->create('bar'));
|
||||
|
||||
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' => []]));
|
||||
filesystem()->file(PATH['project'] . '/media/.meta/foo/foo.txt.yaml')->put(flextype('serializers')->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'));
|
||||
$this->assertFalse(flextype('media.files')->copy('foo/foo.txt', 'bar/foo.txt'));
|
||||
$this->assertTrue(flextype('media')->files()->copy('foo/foo.txt', 'bar/foo.txt'));
|
||||
$this->assertTrue(flextype('media')->files()->copy('foo/foo.txt', 'bar/bar.txt'));
|
||||
$this->assertFalse(flextype('media')->files()->copy('foo/foo.txt', 'bar/foo.txt'));
|
||||
});
|
||||
|
||||
test('test has() method', function () {
|
||||
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/.meta/foo.txt.yaml')->put(flextype('serializers')->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'));
|
||||
$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'] . '/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'));
|
||||
filesystem()->file(PATH['project'] . '/media/.meta/foo.txt.yaml')->put(flextype('serializers')->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'] . '/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'));
|
||||
filesystem()->file(PATH['project'] . '/media/.meta/foo.txt.yaml')->put(flextype('serializers')->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'));
|
||||
});
|
||||
|
@@ -14,5 +14,5 @@ afterEach(function (): void {
|
||||
|
||||
test('test getDirectoryMetaLocation() method', function () {
|
||||
$this->assertStringContainsString('/.meta/foo',
|
||||
flextype('media.folders.meta')->getDirectoryMetaLocation('foo'));
|
||||
flextype('media')->folders()->meta()->getDirectoryMetaLocation('foo'));
|
||||
});
|
||||
|
@@ -14,34 +14,34 @@ afterEach(function (): void {
|
||||
|
||||
|
||||
test('test fetch() method', function () {
|
||||
$this->assertTrue(flextype('media.folders')->create('foo'));
|
||||
$this->assertTrue(flextype('media.folders')->create('foo/bar'));
|
||||
$this->assertTrue(flextype('media.folders')->create('foo/zed'));
|
||||
$this->assertTrue(count(flextype('media.folders')->fetch('foo', ['collection' => true])) == 2);
|
||||
$this->assertTrue(count(flextype('media.folders')->fetch('foo')) > 0);
|
||||
$this->assertTrue(flextype('media')->folders()->create('foo'));
|
||||
$this->assertTrue(flextype('media')->folders()->create('foo/bar'));
|
||||
$this->assertTrue(flextype('media')->folders()->create('foo/zed'));
|
||||
$this->assertTrue(count(flextype('media')->folders()->fetch('foo', ['collection' => true])) == 2);
|
||||
$this->assertTrue(count(flextype('media')->folders()->fetch('foo')) > 0);
|
||||
});
|
||||
|
||||
test('test create() method', function () {
|
||||
$this->assertTrue(flextype('media.folders')->create('foo'));
|
||||
$this->assertTrue(flextype('media')->folders()->create('foo'));
|
||||
});
|
||||
|
||||
test('test move() method', function () {
|
||||
$this->assertTrue(flextype('media.folders')->create('foo'));
|
||||
$this->assertTrue(flextype('media.folders')->move('foo', 'bar'));
|
||||
$this->assertTrue(flextype('media')->folders()->create('foo'));
|
||||
$this->assertTrue(flextype('media')->folders()->move('foo', 'bar'));
|
||||
});
|
||||
|
||||
test('test copy() method', function () {
|
||||
$this->assertTrue(flextype('media.folders')->create('foo'));
|
||||
$this->assertTrue(flextype('media.folders')->copy('foo', 'bar'));
|
||||
$this->assertTrue(flextype('media')->folders()->create('foo'));
|
||||
$this->assertTrue(flextype('media')->folders()->copy('foo', 'bar'));
|
||||
});
|
||||
|
||||
test('test delete() method', function () {
|
||||
$this->assertTrue(flextype('media.folders')->create('foo'));
|
||||
$this->assertTrue(flextype('media.folders')->delete('foo'));
|
||||
$this->assertFalse(flextype('media.folders')->delete('bar'));
|
||||
$this->assertTrue(flextype('media')->folders()->create('foo'));
|
||||
$this->assertTrue(flextype('media')->folders()->delete('foo'));
|
||||
$this->assertFalse(flextype('media')->folders()->delete('bar'));
|
||||
});
|
||||
|
||||
test('test getDirectoryLocation() method', function () {
|
||||
$this->assertStringContainsString('/foo',
|
||||
flextype('media.folders')->getDirectoryLocation('foo'));
|
||||
flextype('media')->folders()->getDirectoryLocation('foo'));
|
||||
});
|
||||
|
Reference in New Issue
Block a user