mirror of
https://github.com/flextype/flextype.git
synced 2025-08-16 10:04:21 +02:00
feat(media): standardise media container names for Media API #517
This commit is contained in:
@@ -16,7 +16,7 @@ afterEach(function (): void {
|
||||
filesystem()->directory(PATH['project'] . '/entries')->delete();
|
||||
});
|
||||
|
||||
test('test media_files field', function () {
|
||||
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' => []]));
|
||||
@@ -25,11 +25,11 @@ test('test media_files field', function () {
|
||||
|
||||
flextype('entries')->create('media', flextype('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];
|
||||
});
|
||||
|
||||
|
@@ -16,7 +16,7 @@ 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' => []]));
|
||||
|
||||
$this->assertTrue(flextype('media_files_meta')->update('foo.txt', 'description', 'Foo description'));
|
||||
$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']);
|
||||
});
|
||||
|
||||
@@ -24,7 +24,7 @@ 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' => []]));
|
||||
|
||||
$this->assertTrue(flextype('media_files_meta')->add('foo.txt', 'bar', 'Bar'));
|
||||
$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']);
|
||||
});
|
||||
|
||||
@@ -32,7 +32,7 @@ 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_meta')->delete('foo.txt', 'title'));
|
||||
$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']));
|
||||
});
|
||||
|
||||
@@ -40,5 +40,5 @@ 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' => []]));
|
||||
$this->assertStringContainsString('foo.txt.yaml',
|
||||
flextype('media_files_meta')->getFileMetaLocation('foo.txt'));
|
||||
flextype('media.files.meta')->getFileMetaLocation('foo.txt'));
|
||||
});
|
||||
|
@@ -18,51 +18,51 @@ test('test fetch() method', function () {
|
||||
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']);
|
||||
$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' => []]));
|
||||
|
||||
$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' => []]));
|
||||
|
||||
$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' => []]));
|
||||
|
||||
$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'));
|
||||
$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'));
|
||||
$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