Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
Test new entry behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-alrek committed Jun 12, 2019
1 parent 3807d46 commit 3bea323
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/functions/common/functions_directories.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"id": 10099,
"name": "Test 3",
"url": "test-3\/",
"revision": 10003,
"published": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"id": 10098,
"name": "Test 3",
"url": "test-3\/",
"revision": 10002,
"published": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"id": 10099,
"name": "Test 3",
"url": "test-3\/",
"revision": 10003,
"published": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"id": 10098,
"name": "Test 3",
"url": "test-3\/",
"revision": 10002,
"published": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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));
}
}

0 comments on commit 3bea323

Please sign in to comment.