From b4b1beebb26be3ed4440adb1d0c86850114e1fc7 Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 4 Dec 2020 20:59:00 +0300 Subject: [PATCH] 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. --- tests/Foundation/Entries/EntriesTest.php | 38 +++++-------------- .../Entries/Fields/CreatedAtFieldTest.php | 2 +- .../Entries/Fields/CreatedByFieldTest.php | 4 +- .../Foundation/Entries/Fields/IdFieldTest.php | 4 +- .../Entries/Fields/ModifiedAtFieldTest.php | 2 +- .../Entries/Fields/ParsersFieldTest.php | 4 +- .../Entries/Fields/PublishedAtFieldTest.php | 2 +- .../Entries/Fields/PublishedByFieldTest.php | 4 +- .../Entries/Fields/RoutableFieldTest.php | 6 +-- .../Entries/Fields/SlugFieldTest.php | 4 +- .../Entries/Fields/UuidFieldTest.php | 2 +- .../Entries/Fields/VisibilityFieldTest.php | 6 +-- tests/Foundation/Media/MediaFilesTest.php | 12 +----- tests/Foundation/Media/MediaFoldersTest.php | 9 +---- 14 files changed, 32 insertions(+), 67 deletions(-) diff --git a/tests/Foundation/Entries/EntriesTest.php b/tests/Foundation/Entries/EntriesTest.php index 86867c6a..30b49770 100644 --- a/tests/Foundation/Entries/EntriesTest.php +++ b/tests/Foundation/Entries/EntriesTest.php @@ -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')); }); diff --git a/tests/Foundation/Entries/Fields/CreatedAtFieldTest.php b/tests/Foundation/Entries/Fields/CreatedAtFieldTest.php index b9fc101e..4d95f539 100644 --- a/tests/Foundation/Entries/Fields/CreatedAtFieldTest.php +++ b/tests/Foundation/Entries/Fields/CreatedAtFieldTest.php @@ -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)); }); diff --git a/tests/Foundation/Entries/Fields/CreatedByFieldTest.php b/tests/Foundation/Entries/Fields/CreatedByFieldTest.php index c97aa8c9..22864492 100644 --- a/tests/Foundation/Entries/Fields/CreatedByFieldTest.php +++ b/tests/Foundation/Entries/Fields/CreatedByFieldTest.php @@ -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); }); diff --git a/tests/Foundation/Entries/Fields/IdFieldTest.php b/tests/Foundation/Entries/Fields/IdFieldTest.php index 129ff73c..f4816037 100644 --- a/tests/Foundation/Entries/Fields/IdFieldTest.php +++ b/tests/Foundation/Entries/Fields/IdFieldTest.php @@ -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); }); diff --git a/tests/Foundation/Entries/Fields/ModifiedAtFieldTest.php b/tests/Foundation/Entries/Fields/ModifiedAtFieldTest.php index 549b60af..6e7a9802 100644 --- a/tests/Foundation/Entries/Fields/ModifiedAtFieldTest.php +++ b/tests/Foundation/Entries/Fields/ModifiedAtFieldTest.php @@ -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)); diff --git a/tests/Foundation/Entries/Fields/ParsersFieldTest.php b/tests/Foundation/Entries/Fields/ParsersFieldTest.php index b7d92fcf..61cf9136 100644 --- a/tests/Foundation/Entries/Fields/ParsersFieldTest.php +++ b/tests/Foundation/Entries/Fields/ParsersFieldTest.php @@ -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('

Foo

', flextype('entries')->fetch('foo')['content']); + $this->assertEquals('

Foo

', 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']); }); diff --git a/tests/Foundation/Entries/Fields/PublishedAtFieldTest.php b/tests/Foundation/Entries/Fields/PublishedAtFieldTest.php index 7d793980..45920678 100644 --- a/tests/Foundation/Entries/Fields/PublishedAtFieldTest.php +++ b/tests/Foundation/Entries/Fields/PublishedAtFieldTest.php @@ -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)); diff --git a/tests/Foundation/Entries/Fields/PublishedByFieldTest.php b/tests/Foundation/Entries/Fields/PublishedByFieldTest.php index abd77bc7..b3a9067c 100644 --- a/tests/Foundation/Entries/Fields/PublishedByFieldTest.php +++ b/tests/Foundation/Entries/Fields/PublishedByFieldTest.php @@ -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); }); diff --git a/tests/Foundation/Entries/Fields/RoutableFieldTest.php b/tests/Foundation/Entries/Fields/RoutableFieldTest.php index cf89a370..9845962d 100644 --- a/tests/Foundation/Entries/Fields/RoutableFieldTest.php +++ b/tests/Foundation/Entries/Fields/RoutableFieldTest.php @@ -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); }); diff --git a/tests/Foundation/Entries/Fields/SlugFieldTest.php b/tests/Foundation/Entries/Fields/SlugFieldTest.php index 3e8feeba..09e5ca69 100644 --- a/tests/Foundation/Entries/Fields/SlugFieldTest.php +++ b/tests/Foundation/Entries/Fields/SlugFieldTest.php @@ -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); }); diff --git a/tests/Foundation/Entries/Fields/UuidFieldTest.php b/tests/Foundation/Entries/Fields/UuidFieldTest.php index 586a63bb..9e43b713 100644 --- a/tests/Foundation/Entries/Fields/UuidFieldTest.php +++ b/tests/Foundation/Entries/Fields/UuidFieldTest.php @@ -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)); }); diff --git a/tests/Foundation/Entries/Fields/VisibilityFieldTest.php b/tests/Foundation/Entries/Fields/VisibilityFieldTest.php index 888173dd..6ba5878b 100644 --- a/tests/Foundation/Entries/Fields/VisibilityFieldTest.php +++ b/tests/Foundation/Entries/Fields/VisibilityFieldTest.php @@ -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); }); diff --git a/tests/Foundation/Media/MediaFilesTest.php b/tests/Foundation/Media/MediaFilesTest.php index b11b2346..7ff2907c 100644 --- a/tests/Foundation/Media/MediaFilesTest.php +++ b/tests/Foundation/Media/MediaFilesTest.php @@ -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']); }); diff --git a/tests/Foundation/Media/MediaFoldersTest.php b/tests/Foundation/Media/MediaFoldersTest.php index ede7839b..71a43fd9 100644 --- a/tests/Foundation/Media/MediaFoldersTest.php +++ b/tests/Foundation/Media/MediaFoldersTest.php @@ -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 () {