1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-16 10:04:21 +02:00

feat(media-folders): add fetch() method with ability to execute different methods with fetch prefix. #509

This commit is contained in:
Awilum
2020-12-17 16:45:22 +03:00
parent 3cd9fde427
commit e810d468ce
4 changed files with 101 additions and 115 deletions

View File

@@ -12,24 +12,17 @@ afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/uploads')->delete();
});
test('test fetchSingle() method', function () {
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' => []]));
$this->assertTrue(count(flextype('media_files')->fetchSingle('foo.txt')) > 0);
$this->assertEquals('Foo', flextype('media_files')->fetchSingle('foo.txt')['title']);
});
$this->assertTrue(count(flextype('media_files')->fetch('foo.txt')) > 0);
$this->assertEquals('Foo', flextype('media_files')->fetch('foo.txt')['title']);
test('test fetchCollection() 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' => []]));
$this->assertTrue(count(flextype('media_files')->fetchCollection('/')) == 2);
$this->assertEquals('Foo', flextype('media_files')->fetchCollection('/')['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 () {

View File

@@ -13,18 +13,12 @@ afterEach(function (): void {
});
test('test fetchCollection() method', function () {
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')->fetchCollection('foo')) == 2);
});
test('test fetchSingle() 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')->fetchSingle('foo')) > 0);
$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 () {