From 3bea32383aff9b2d7e7f0b866c3c24f0e31f8605 Mon Sep 17 00:00:00 2001 From: Thomas Alrek Date: Wed, 12 Jun 2019 10:31:31 +0200 Subject: [PATCH] Test new entry behavior --- .../common/functions_directories.php | 5 ++- ...EntryTest__testCanOverrideRevision__2.json | 7 ++++ ...EntryTest__testCanOverrideRevision__3.json | 7 ++++ ...EntryTest__testCanOverrideRevision__2.json | 7 ++++ ...EntryTest__testCanOverrideRevision__3.json | 7 ++++ .../common.get_directory_entry.test.php | 24 ++++++++++++ .../common.get_entry.test.php | 37 +++++++++++++++++++ 7 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 tests/TestSuites/Common/function_directories/__snapshots__/Common_GetDirectoryEntryTest__testCanOverrideRevision__2.json create mode 100644 tests/TestSuites/Common/function_directories/__snapshots__/Common_GetDirectoryEntryTest__testCanOverrideRevision__3.json create mode 100644 tests/TestSuites/Common/function_directories/__snapshots__/Common_GetEntryTest__testCanOverrideRevision__2.json create mode 100644 tests/TestSuites/Common/function_directories/__snapshots__/Common_GetEntryTest__testCanOverrideRevision__3.json diff --git a/src/functions/common/functions_directories.php b/src/functions/common/functions_directories.php index bbc0431..4d03440 100644 --- a/src/functions/common/functions_directories.php +++ b/src/functions/common/functions_directories.php @@ -8,10 +8,11 @@ */ function get_directory_entry($id) { + global $entry_override; global $revision_override; $id = convert_to_safe_string($id, 'int'); - $entrydata = $revision_override ? null : NF::$cache->fetch("entry/$id"); + $entrydata = (isset($entry_override) && $entry_override == $id && isset($revision_override)) ? null : NF::$cache->fetch("entry/$id"); if ($entrydata == null) { $url = 'builder/structures/entry/' . $id; @@ -56,7 +57,7 @@ function get_directory_entry($id) NF::debug($entrydata, 'entry ' . $id . ' from memory'); } - if ($entrydata && ($entrydata['published']) || $revision_override) { + if ($entrydata && ($entrydata['published']) || ($entry_override == $id && isset($revision_override))) { return $entrydata; } } diff --git a/tests/TestSuites/Common/function_directories/__snapshots__/Common_GetDirectoryEntryTest__testCanOverrideRevision__2.json b/tests/TestSuites/Common/function_directories/__snapshots__/Common_GetDirectoryEntryTest__testCanOverrideRevision__2.json new file mode 100644 index 0000000..a71c597 --- /dev/null +++ b/tests/TestSuites/Common/function_directories/__snapshots__/Common_GetDirectoryEntryTest__testCanOverrideRevision__2.json @@ -0,0 +1,7 @@ +{ + "id": 10099, + "name": "Test 3", + "url": "test-3\/", + "revision": 10003, + "published": false +} diff --git a/tests/TestSuites/Common/function_directories/__snapshots__/Common_GetDirectoryEntryTest__testCanOverrideRevision__3.json b/tests/TestSuites/Common/function_directories/__snapshots__/Common_GetDirectoryEntryTest__testCanOverrideRevision__3.json new file mode 100644 index 0000000..ef43006 --- /dev/null +++ b/tests/TestSuites/Common/function_directories/__snapshots__/Common_GetDirectoryEntryTest__testCanOverrideRevision__3.json @@ -0,0 +1,7 @@ +{ + "id": 10098, + "name": "Test 3", + "url": "test-3\/", + "revision": 10002, + "published": true +} diff --git a/tests/TestSuites/Common/function_directories/__snapshots__/Common_GetEntryTest__testCanOverrideRevision__2.json b/tests/TestSuites/Common/function_directories/__snapshots__/Common_GetEntryTest__testCanOverrideRevision__2.json new file mode 100644 index 0000000..a71c597 --- /dev/null +++ b/tests/TestSuites/Common/function_directories/__snapshots__/Common_GetEntryTest__testCanOverrideRevision__2.json @@ -0,0 +1,7 @@ +{ + "id": 10099, + "name": "Test 3", + "url": "test-3\/", + "revision": 10003, + "published": false +} diff --git a/tests/TestSuites/Common/function_directories/__snapshots__/Common_GetEntryTest__testCanOverrideRevision__3.json b/tests/TestSuites/Common/function_directories/__snapshots__/Common_GetEntryTest__testCanOverrideRevision__3.json new file mode 100644 index 0000000..ef43006 --- /dev/null +++ b/tests/TestSuites/Common/function_directories/__snapshots__/Common_GetEntryTest__testCanOverrideRevision__3.json @@ -0,0 +1,7 @@ +{ + "id": 10098, + "name": "Test 3", + "url": "test-3\/", + "revision": 10002, + "published": true +} diff --git a/tests/TestSuites/Common/function_directories/common.get_directory_entry.test.php b/tests/TestSuites/Common/function_directories/common.get_directory_entry.test.php index 24ec7d4..3730c48 100644 --- a/tests/TestSuites/Common/function_directories/common.get_directory_entry.test.php +++ b/tests/TestSuites/Common/function_directories/common.get_directory_entry.test.php @@ -52,6 +52,7 @@ public function testHandlesNotFound (): void public function testCanOverrideRevision (): void { global $revision_override; + global $entry_override; NF::$cache->mockItem('entry/10003', [ 'id' => 10003, @@ -69,9 +70,32 @@ public function testCanOverrideRevision (): void 'published' => false ]))); + $entry_override = 10003; $revision_override = 10001; $this->assertMatchesJsonSnapshot(get_directory_entry(10003)); + + NF::$cache->mockItem('entry/10098', [ + 'id' => 10098, + 'name' => 'Test 3', + 'url' => 'test-3/', + 'revision' => 10002, + 'published' => true + ]); + + NF::$capi->mockResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode([ + 'id' => 10099, + 'name' => 'Test 3', + 'url' => 'test-3/', + 'revision' => 10003, + 'published' => false + ]))); + + $entry_override = 10099; + $revision_override = 10003; + + $this->assertMatchesJsonSnapshot(get_directory_entry(10099)); + $this->assertMatchesJsonSnapshot(get_directory_entry(10098)); } public function testRespectsPublishedAttribute (): void diff --git a/tests/TestSuites/Common/function_directories/common.get_entry.test.php b/tests/TestSuites/Common/function_directories/common.get_entry.test.php index 876b00b..8d4e1f7 100644 --- a/tests/TestSuites/Common/function_directories/common.get_entry.test.php +++ b/tests/TestSuites/Common/function_directories/common.get_entry.test.php @@ -52,6 +52,7 @@ public function testHandlesNotFound (): void public function testCanOverrideRevision (): void { global $revision_override; + global $entry_override; NF::$cache->mockItem('entry/10003', [ 'id' => 10003, @@ -69,9 +70,45 @@ public function testCanOverrideRevision (): void 'published' => false ]))); + $entry_override = 10003; $revision_override = 10001; $this->assertMatchesJsonSnapshot(get_entry(10003)); + + NF::$cache->mockItem('entry/10098', [ + 'id' => 10098, + 'name' => 'Test 3', + 'url' => 'test-3/', + 'revision' => 10002, + 'published' => true + ]); + + NF::$capi->mockResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode([ + 'id' => 10099, + 'name' => 'Test 3', + 'url' => 'test-3/', + 'revision' => 10003, + 'published' => false + ]))); + + $entry_override = 10099; + $revision_override = 10003; + + $this->assertMatchesJsonSnapshot(get_entry(10099)); + $this->assertMatchesJsonSnapshot(get_entry(10098)); + } + + public function testRespectsPublishedAttribute (): void + { + NF::$capi->mockResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode([ + 'id' => 10004, + 'name' => 'Test 4', + 'url' => 'test-4/', + 'revision' => 10000, + 'published' => false + ]))); + + $this->assertNull(get_entry(10004)); } }