From fe7eb314ac1a0085785bd0ae6b211c16acb61b78 Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 11 Dec 2020 00:32:00 +0300 Subject: [PATCH] feat(entries): Entries API fetch improvements. #491 BREAKING CHANGES events changes: onEntriesFetch onEntriesFetchSingle instead of onEntryInitialized onEntriesFetchSingleAfterCacheInitialized instead of onEntryAfterCacheInitialized onEntriesFetchSingleAfterInitialized instead of onEntryAfterInitialized onEntriesFetchCollection instead of onEntriesInitialized onEntriesFetchCollectionAfterInitialized instead of onEntriesAfterInitialized onEntriesMove instead of onEntryMove onEntriesUpdate instead of onEntryUpdate onEntriesCreate instead of onEntryCreate onEntriesDelete instead of onEntryDelete onEntriesCopy instead of onEntryCopy onEntriesHas instead of onEntryHas --- tests/Foundation/Entries/EntriesTest.php | 31 +++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/tests/Foundation/Entries/EntriesTest.php b/tests/Foundation/Entries/EntriesTest.php index e7591d90..167ab3ce 100644 --- a/tests/Foundation/Entries/EntriesTest.php +++ b/tests/Foundation/Entries/EntriesTest.php @@ -27,6 +27,31 @@ test('test update() method', function () { $this->assertFalse(flextype('entries')->update('bar', ['title' => 'Test'])); }); +test('test fetch() entry', function () { + flextype('entries')->create('foo', ['title' => 'Foo']); + flextype('entries')->create('foo/bar', ['title' => 'Bar']); + flextype('entries')->create('foo/baz', ['title' => 'Baz']); + flextype('entries')->create('foo/zed', ['title' => 'Zed']); + + $this->assertEquals(12, flextype('entries')->fetch('foo')->count()); + $this->assertEquals(12, flextype('entries')->fetch('foo', ['collection' => false])->count()); + $this->assertEquals(3, flextype('entries')->fetch('foo', ['collection' => true])->count()); + + $this->assertEquals('Bar', flextype('entries')->fetch('foo/bar')['title']); + $this->assertEquals('Baz', flextype('entries')->fetch('foo/baz')['title']); + $this->assertEquals('Zed', flextype('entries')->fetch('foo/zed')['title']); + + flextype('emitter')->addListener('onEntriesFetchCollectionAfterInitialized', static function (): void { + flextype('entries')->setStorage('fetch.data.foo/zed.title', 'ZedFromCollection!'); + }); + + flextype('emitter')->addListener('onEntriesFetchCollectionAfterInitialized', static function (): void { + flextype('entries')->setStorage('fetch.data.foo/baz.title', 'BazFromCollection!'); + }); + + $this->assertEquals('ZedFromCollection!', flextype('entries')->fetch('foo', ['collection' => true])['foo/zed.title']); + $this->assertEquals('BazFromCollection!', flextype('entries')->fetch('foo', ['collection' => true])['foo/baz.title']); +}); test('test fetchSingle() method', function () { // 1 @@ -92,14 +117,14 @@ test('test getFileLocation() method', function () { flextype('entries')->getFileLocation('foo')); }); -test('test getDirectoryLocation entry', function () { +test('test getDirectoryLocation() entry', function () { flextype('entries')->create('foo', []); $this->assertStringContainsString('/foo', flextype('entries')->getDirectoryLocation('foo')); }); -test('test getCacheID entry', function () { +test('test getCacheID() entry', function () { flextype('registry')->set('flextype.settings.cache.enabled', false); flextype('entries')->create('foo', []); $this->assertEquals('', flextype('entries')->getCacheID('foo')); @@ -111,7 +136,7 @@ test('test getCacheID entry', function () { flextype('registry')->set('flextype.settings.cache.enabled', false); }); -test('test setStorage and getStorage entry', function () { +test('test setStorage() and getStorage() entry', function () { flextype('entries')->setStorage('foo', ['title' => 'Foo']); flextype('entries')->setStorage('bar', ['title' => 'Bar']); $this->assertEquals('Foo', flextype('entries')->getStorage('foo')['title']);