mirror of
https://github.com/flextype/flextype.git
synced 2025-08-09 06:36:52 +02:00
Standardize Media Folders API fetch. #488
BREAKING CHANGES method fetch() removed and instead of it should be used fetchSingle() and fetchCollection() methods fetchSingle() and fetchCollection() return an instance of Atomastic Arrays.
This commit is contained in:
@@ -27,28 +27,6 @@ test('test update() method', function () {
|
||||
$this->assertFalse(flextype('entries')->update('bar', ['title' => 'Test']));
|
||||
});
|
||||
|
||||
test('test fetch() method', function () {
|
||||
// 1
|
||||
flextype('entries')->create('foo', []);
|
||||
$fetch = flextype('entries')->fetch('foo');
|
||||
$this->assertTrue(count($fetch) > 0);
|
||||
|
||||
// 2
|
||||
$this->assertEquals([], flextype('entries')->fetch('bar')->toArray());
|
||||
|
||||
// 3
|
||||
flextype('entries')->create('zed', ['title' => 'Zed']);
|
||||
$fetch = flextype('entries')->fetch('zed');
|
||||
$this->assertEquals('Zed', $fetch['title']);
|
||||
|
||||
// 4
|
||||
flextype('entries')->create('foo', []);
|
||||
flextype('entries')->create('foo/bar', []);
|
||||
flextype('entries')->create('foo/baz', ['foo' => ['bar' => 'zed']]);
|
||||
$fetch = flextype('entries')->fetch('foo', true)->toArray();
|
||||
$this->assertTrue(count($fetch) > 0);
|
||||
|
||||
});
|
||||
|
||||
test('test fetchSingle() method', function () {
|
||||
// 1
|
||||
@@ -57,23 +35,23 @@ test('test fetchSingle() method', function () {
|
||||
$this->assertTrue(count($fetch) > 0);
|
||||
|
||||
// 2
|
||||
$this->assertEquals([], flextype('entries')->fetchSingle('bar')->toArray());
|
||||
$this->assertEquals('foo', flextype('entries')->fetchSingle('foo')['id']);
|
||||
|
||||
// 3
|
||||
flextype('entries')->create('zed', ['title' => 'Zed']);
|
||||
$fetch = flextype('entries')->fetchSingle('zed')->toArray();
|
||||
$fetch = flextype('entries')->fetchSingle('zed');
|
||||
$this->assertEquals('Zed', $fetch['title']);
|
||||
|
||||
// 4
|
||||
flextype('entries')->setStorage('fetch_single.id', 'wrong-entry');
|
||||
$this->assertEquals([], flextype('entries')->fetchSingle('wrong-entry')->toArray());
|
||||
flextype('entries')->setStorage('fetch.id', 'wrong-entry');
|
||||
$this->assertEquals(0, flextype('entries')->fetchSingle('wrong-entry')->count());
|
||||
});
|
||||
|
||||
test('test fetchCollection() method', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
flextype('entries')->create('foo/bar', []);
|
||||
flextype('entries')->create('foo/baz', []);
|
||||
$fetch = flextype('entries')->fetchCollection('foo')->toArray();
|
||||
flextype('entries')->create('foo/bar', ['title' => 'Bar']);
|
||||
flextype('entries')->create('foo/baz', ['title' => 'Baz']);
|
||||
$fetch = flextype('entries')->fetchCollection('foo');
|
||||
$this->assertTrue(count($fetch) > 0);
|
||||
});
|
||||
|
||||
@@ -138,4 +116,6 @@ test('test setStorage and getStorage entry', function () {
|
||||
flextype('entries')->setStorage('bar', ['title' => 'Bar']);
|
||||
$this->assertEquals('Foo', flextype('entries')->getStorage('foo')['title']);
|
||||
$this->assertEquals('Bar', flextype('entries')->getStorage('bar')['title']);
|
||||
$this->assertEquals('Foo', flextype('entries')->getStorage('foo.title'));
|
||||
$this->assertEquals('Bar', flextype('entries')->getStorage('bar.title'));
|
||||
});
|
||||
|
@@ -13,7 +13,7 @@ afterEach(function (): void {
|
||||
test('test CreatedAtField', function () {
|
||||
// 1
|
||||
flextype('entries')->create('foo', []);
|
||||
$created_at = flextype('entries')->fetch('foo')['created_at'];
|
||||
$created_at = flextype('entries')->fetchSingle('foo')['created_at'];
|
||||
$this->assertTrue(strlen($created_at) > 0);
|
||||
$this->assertTrue((ctype_digit($created_at) && strtotime(date('Y-m-d H:i:s', $created_at)) === (int)$created_at));
|
||||
});
|
||||
|
@@ -12,10 +12,10 @@ afterEach(function (): void {
|
||||
|
||||
test('test CreatedByField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$created_by = flextype('entries')->fetch('foo')['created_by'];
|
||||
$created_by = flextype('entries')->fetchSingle('foo')['created_by'];
|
||||
$this->assertEquals('', $created_by);
|
||||
|
||||
flextype('entries')->create('bar', ['created_by' => 'Zed']);
|
||||
$created_by = flextype('entries')->fetch('bar')['created_by'];
|
||||
$created_by = flextype('entries')->fetchSingle('bar')['created_by'];
|
||||
$this->assertEquals('Zed', $created_by);
|
||||
});
|
||||
|
@@ -12,10 +12,10 @@ afterEach(function (): void {
|
||||
|
||||
test('test IdField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$id = flextype('entries')->fetch('foo')['id'];
|
||||
$id = flextype('entries')->fetchSingle('foo')['id'];
|
||||
$this->assertEquals('foo', $id);
|
||||
|
||||
flextype('entries')->create('foo/bar', []);
|
||||
$id = flextype('entries')->fetch('foo/bar')['id'];
|
||||
$id = flextype('entries')->fetchSingle('foo/bar')['id'];
|
||||
$this->assertEquals('foo/bar', $id);
|
||||
});
|
||||
|
@@ -13,7 +13,7 @@ afterEach(function (): void {
|
||||
test('test ModifiedAtField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
|
||||
$modified_at = flextype('entries')->fetch('foo')['modified_at'];
|
||||
$modified_at = flextype('entries')->fetchSingle('foo')['modified_at'];
|
||||
|
||||
$this->assertTrue(strlen($modified_at) > 0);
|
||||
$this->assertTrue((ctype_digit($modified_at) && strtotime(date('Y-m-d H:i:s', $modified_at)) === (int)$modified_at));
|
||||
|
@@ -12,8 +12,8 @@ afterEach(function (): void {
|
||||
|
||||
test('test ParsersField', function () {
|
||||
flextype('entries')->create('foo', ['content' => '#Foo', 'parsers' => ['markdown' => ['enabled' => true, 'fields' => ['content']]]]);
|
||||
$this->assertEquals('<h1>Foo</h1>', flextype('entries')->fetch('foo')['content']);
|
||||
$this->assertEquals('<h1>Foo</h1>', flextype('entries')->fetchSingle('foo')['content']);
|
||||
|
||||
flextype('entries')->create('bar', ['content' => '[registry_get name="Bar" default="Zed"]', 'parsers' => ['shortcode' => ['enabled' => true, 'fields' => ['content']]]]);
|
||||
$this->assertEquals('Zed', flextype('entries')->fetch('bar')['content']);
|
||||
$this->assertEquals('Zed', flextype('entries')->fetchSingle('bar')['content']);
|
||||
});
|
||||
|
@@ -13,7 +13,7 @@ afterEach(function (): void {
|
||||
test('test PublishedAtField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
|
||||
$published_at = flextype('entries')->fetch('foo')['published_at'];
|
||||
$published_at = flextype('entries')->fetchSingle('foo')['published_at'];
|
||||
|
||||
$this->assertTrue(strlen($published_at) > 0);
|
||||
$this->assertTrue((ctype_digit($published_at) && strtotime(date('Y-m-d H:i:s', $published_at)) === (int)$published_at));
|
||||
|
@@ -12,10 +12,10 @@ afterEach(function (): void {
|
||||
|
||||
test('test PublishedByField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$published_by = flextype('entries')->fetch('foo')['published_by'];
|
||||
$published_by = flextype('entries')->fetchSingle('foo')['published_by'];
|
||||
$this->assertEquals('', $published_by);
|
||||
|
||||
flextype('entries')->create('bar', ['published_by' => 'Zed']);
|
||||
$published_by = flextype('entries')->fetch('bar')['published_by'];
|
||||
$published_by = flextype('entries')->fetchSingle('bar')['published_by'];
|
||||
$this->assertEquals('Zed', $published_by);
|
||||
});
|
||||
|
@@ -14,14 +14,14 @@ test('test RoutableField', function () {
|
||||
flextype('registry')->set('flextype.settings.cache.enabled', false);
|
||||
|
||||
flextype('entries')->create('foo', ['routable' => true]);
|
||||
$routable = flextype('entries')->fetch('foo')['routable'];
|
||||
$routable = flextype('entries')->fetchSingle('foo')['routable'];
|
||||
$this->assertTrue($routable);
|
||||
|
||||
flextype('entries')->create('bar', []);
|
||||
$routable = flextype('entries')->fetch('bar')['routable'];
|
||||
$routable = flextype('entries')->fetchSingle('bar')['routable'];
|
||||
$this->assertTrue($routable);
|
||||
|
||||
flextype('entries')->create('zed', ['routable' => false]);
|
||||
$routable = flextype('entries')->fetch('zed')['routable'];
|
||||
$routable = flextype('entries')->fetchSingle('zed')['routable'];
|
||||
$this->assertFalse($routable);
|
||||
});
|
||||
|
@@ -12,10 +12,10 @@ afterEach(function (): void {
|
||||
|
||||
test('test SlugField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$slug = flextype('entries')->fetch('foo')['slug'];
|
||||
$slug = flextype('entries')->fetchSingle('foo')['slug'];
|
||||
$this->assertEquals('foo', $slug);
|
||||
|
||||
flextype('entries')->create('bar', []);
|
||||
$slug = flextype('entries')->fetch('bar')['slug'];
|
||||
$slug = flextype('entries')->fetchSingle('bar')['slug'];
|
||||
$this->assertEquals('bar', $slug);
|
||||
});
|
||||
|
@@ -14,6 +14,6 @@ afterEach(function (): void {
|
||||
|
||||
test('test UuidField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$uuid = flextype('entries')->fetch('foo')['uuid'];
|
||||
$uuid = flextype('entries')->fetchSingle('foo')['uuid'];
|
||||
$this->assertTrue(v::uuid()->validate($uuid));
|
||||
});
|
||||
|
@@ -12,14 +12,14 @@ afterEach(function (): void {
|
||||
|
||||
test('test VisibilityField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$visibility = flextype('entries')->fetch('foo')['visibility'];
|
||||
$visibility = flextype('entries')->fetchSingle('foo')['visibility'];
|
||||
$this->assertEquals('visible', $visibility);
|
||||
|
||||
flextype('entries')->create('bar', ['visibility' => 'draft']);
|
||||
$visibility = flextype('entries')->fetch('bar')['visibility'];
|
||||
$visibility = flextype('entries')->fetchSingle('bar')['visibility'];
|
||||
$this->assertEquals('draft', $visibility);
|
||||
|
||||
flextype('entries')->create('zed', ['visibility' => 'foobar']);
|
||||
$visibility = flextype('entries')->fetch('zed')['visibility'];
|
||||
$visibility = flextype('entries')->fetchSingle('zed')['visibility'];
|
||||
$this->assertEquals('visible', $visibility);
|
||||
});
|
||||
|
@@ -12,22 +12,12 @@ afterEach(function (): void {
|
||||
filesystem()->directory(PATH['project'] . '/uploads')->delete();
|
||||
});
|
||||
|
||||
test('test fetch() method', function () {
|
||||
test('test fetchSingle() 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')->fetch('foo.txt')) > 0);
|
||||
$this->assertEquals('Foo', flextype('media_files')->fetch('foo.txt')['title']);
|
||||
$this->assertTrue(count(flextype('media_files')->fetch('/', true)) == 2);
|
||||
$this->assertEquals('Foo', flextype('media_files')->fetch('/', true)['foo.txt']['title']);
|
||||
});
|
||||
|
||||
test('test fetchSingle() 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' => []]));
|
||||
|
||||
$this->assertTrue(count(flextype('media_files')->fetchSingle('foo.txt')) > 0);
|
||||
$this->assertEquals('Foo', flextype('media_files')->fetchSingle('foo.txt')['title']);
|
||||
});
|
||||
|
@@ -12,10 +12,6 @@ afterEach(function (): void {
|
||||
filesystem()->directory(PATH['project'] . '/uploads')->delete();
|
||||
});
|
||||
|
||||
test('test fetchSingle() method', function () {
|
||||
$this->assertTrue(flextype('media_folders')->create('foo'));
|
||||
$this->assertTrue(count(flextype('media_folders')->fetchSingle('foo')) > 0);
|
||||
});
|
||||
|
||||
test('test fetchCollection() method', function () {
|
||||
$this->assertTrue(flextype('media_folders')->create('foo'));
|
||||
@@ -24,12 +20,11 @@ test('test fetchCollection() method', function () {
|
||||
$this->assertTrue(count(flextype('media_folders')->fetchCollection('foo')) == 2);
|
||||
});
|
||||
|
||||
test('test fetch() method', function () {
|
||||
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')->fetch('foo')) > 0);
|
||||
$this->assertTrue(count(flextype('media_folders')->fetch('foo', true)) == 2);
|
||||
$this->assertTrue(count(flextype('media_folders')->fetchSingle('foo')) > 0);
|
||||
});
|
||||
|
||||
test('test create() method', function () {
|
||||
|
Reference in New Issue
Block a user