diff --git a/tests/Prismic/ApiDataTest.php b/tests/Prismic/ApiDataTest.php index c03c3dd9..38ae2de9 100644 --- a/tests/Prismic/ApiDataTest.php +++ b/tests/Prismic/ApiDataTest.php @@ -36,6 +36,14 @@ public function testWithJsonStringThrowsExceptionForInvalidJson() ApiData::withJsonString('wtf?'); } + public function testApiDataWorksWithoutBookmarks(){ + $json = $this->getJsonFixture('data-without-bookmarks.json'); + $data = ApiData::withJsonString($json); + + $this->assertInstanceOf(ApiData::class, $data); + $this->assertEquals([], $data->getBookmarks()); + } + public function testApiDataHasExpectedValues() { $this->assertCount(3, $this->data->getRefs()); diff --git a/tests/Prismic/ApiTest.php b/tests/Prismic/ApiTest.php index b66de732..fd0a4861 100755 --- a/tests/Prismic/ApiTest.php +++ b/tests/Prismic/ApiTest.php @@ -201,6 +201,25 @@ public function testBookmarkReturnsCorrectDocumentId() $this->assertNull($api->bookmark('unknown-bookmark')); } + public function testApiWorksWithoutBookmarks() { + // Create an ApiData object without bookmarks + $data = $this->getJsonFixture('data-without-bookmarks.json'); + $apiData = ApiData::withJsonString($data); + + // Cache the data + $key = 'https://whatever.prismic.io/api/v2#My-Access-Token'; + $cachedData = serialize($apiData); + $this->cache->get($key)->willReturn($cachedData); + $this->httpClient->request()->shouldNotBeCalled(); + + $api = $this->getApi(); + + // Test that the bookmarks are empty + $this->assertEmpty($api->bookmarks()); + $this->assertNull($api->bookmark('about')); + $this->assertNull($api->bookmark('unknown-bookmark')); + } + public function testFormsReturnsOnlyFormInstances() { $api = $this->getApiWithDefaultData(); diff --git a/tests/fixtures/data-without-bookmarks.json b/tests/fixtures/data-without-bookmarks.json new file mode 100644 index 00000000..8616e123 --- /dev/null +++ b/tests/fixtures/data-without-bookmarks.json @@ -0,0 +1,165 @@ +{ + "refs": [ + { + "id": "master", + "ref": "UgjWQN_mqa8HvPJY", + "label": "Master", + "isMasterRef": true + }, + { + "id": "UkL0hcuvzYUANCrr", + "ref": "UgjWRd_mqbYHvPJa", + "label": "San Francisco Grand opening" + }, + { + "id": "SaGrandOpening2ndRef", + "ref": "SaGrandOpening2ndRef", + "label": "San Francisco Grand opening" + } + ], + "types": { + "blog-post": "Blog post", + "store": "Store", + "article": "Site-level article", + "selection": "Products selection", + "job-offer": "Job offer", + "product": "Product" + }, + "languages": [ + { + "id": "en-us", + "name": "English - United States" + }, + { + "id": "nl-nl", + "name": "Dutch - Netherlands" + }, + { + "id": "es-es", + "name": "Spanish - Spain (Traditional)" + }, + { + "id": "fr-fr", + "name": "French - France" + } + ], + "tags": ["Cupcake", "Pie", "Featured", "Macaron"], + "forms": { + "everything": { + "method": "GET", + "enctype": "application/x-www-form-urlencoded", + "action": "http://lesbonneschoses.prismic.io/api/v2/documents/search", + "fields": { + "ref": { + "type": "String" + }, + "q": { + "type": "String" + } + } + }, + "blogs": { + "name": "Blog Posts", + "method": "GET", + "rel": "collection", + "enctype": "application/x-www-form-urlencoded", + "action": "https://lesbonneschoses.prismic.io/api/v2/documents/search", + "fields": { + "ref": { + "type": "String", + "multiple": false + }, + "q": { + "default": "[[:d = any(document.type, [\"blog-post\"])]]", + "type": "String", + "multiple": true + }, + "lang": { + "type": "String", + "multiple": false + }, + "page": { + "type": "Integer", + "multiple": false, + "default": "1" + }, + "pageSize": { + "type": "Integer", + "multiple": false, + "default": "20" + }, + "after": { + "type": "String", + "multiple": false + }, + "fetch": { + "type": "String", + "multiple": false + }, + "fetchLinks": { + "type": "String", + "multiple": false + }, + "graphQuery": { + "type": "String", + "multiple": false + }, + "orderings": { + "type": "String", + "multiple": false + }, + "referer": { + "type": "String", + "multiple": false + }, + "access_token": { + "default": "a-permanent-access-token", + "type": "String", + "multiple": false + } + } + } + }, + "oauth_initiate": "http://lesbonneschoses.prismic.io/auth", + "oauth_token": "http://lesbonneschoses.prismic.io/auth/token", + "experiments" : { + "draft": [ + { + "id": "xxxxxxxxxxoGelsX", + "name": "Exp 2", + "variations": [ + { + "id": "VDUBBawGAKoGelsZ", + "label": "Base", + "ref": "VDUBBawGALAGelsa" + }, + { + "id": "VDUE-awGALAGemME", + "label": "var 1", + "ref": "VDUUmHIKAZQKk9uq" + } + ] + } + ], + "running": [ + { + "googleId": "_UQtin7EQAOH5M34RQq6Dg", + "id": "VDUBBawGAKoGelsX", + "name": "Exp 1", + "variations": [ + { + "id": "VDUBBawGAKoGelsZ", + "label": "Base", + "ref": "VDUBBawGALAGelsa" + }, + { + "id": "VDUE-awGALAGemME", + "label": "var 1", + "ref": "VDUUmHIKAZQKk9uq" + } + ] + } + ] + } + +}