]> BookStack Code Mirror - bookstack/blobdiff - tests/Entity/PageTemplateTest.php
Updated callout link formatting
[bookstack] / tests / Entity / PageTemplateTest.php
index 17450f49478e882ee05ce7b24c7feb7c978deaab..8eba1355792f593be11a7431c6f6866eaa3732cc 100644 (file)
@@ -1,4 +1,4 @@
-<?php namespace Entity;
+<?php namespace Tests\Entity;
 
 use BookStack\Entities\Page;
 use Tests\TestCase;
@@ -47,4 +47,44 @@ class PageTemplateTest extends TestCase
         ]);
     }
 
+    public function test_templates_content_should_be_fetchable_only_if_page_marked_as_template()
+    {
+        $content = '<div>my_custom_template_content</div>';
+        $page = Page::first();
+        $editor = $this->getEditor();
+        $this->actingAs($editor);
+
+        $templateFetch = $this->get('/templates/' . $page->id);
+        $templateFetch->assertStatus(404);
+
+        $page->html = $content;
+        $page->template = true;
+        $page->save();
+
+        $templateFetch = $this->get('/templates/' . $page->id);
+        $templateFetch->assertStatus(200);
+        $templateFetch->assertJson([
+            'html' => $content,
+            'markdown' => '',
+        ]);
+    }
+
+    public function test_template_endpoint_returns_paginated_list_of_templates()
+    {
+        $editor = $this->getEditor();
+        $this->actingAs($editor);
+
+        $toBeTemplates = Page::query()->orderBy('name', 'asc')->take(12)->get();
+        $page = $toBeTemplates->first();
+
+        $emptyTemplatesFetch = $this->get('/templates');
+        $emptyTemplatesFetch->assertDontSee($page->name);
+
+        Page::query()->whereIn('id', $toBeTemplates->pluck('id')->toArray())->update(['template' => true]);
+
+        $templatesFetch = $this->get('/templates');
+        $templatesFetch->assertSee($page->name);
+        $templatesFetch->assertSee('pagination');
+    }
+
 }
\ No newline at end of file