]> BookStack Code Mirror - bookstack/blobdiff - tests/Entity/ExportTest.php
Fixes for CodeStyle vol.2
[bookstack] / tests / Entity / ExportTest.php
index f437904e842517375b20599142a538f07ebfe0ab..7031c3875a77edb925527d4dc4cd272d18111e55 100644 (file)
@@ -1,5 +1,8 @@
-<?php namespace Tests\Entity;
+<?php
 
+namespace Tests\Entity;
+
+use BookStack\Auth\Role;
 use BookStack\Entities\Models\Book;
 use BookStack\Entities\Models\Chapter;
 use BookStack\Entities\Models\Page;
@@ -9,7 +12,6 @@ use Tests\TestCase;
 
 class ExportTest extends TestCase
 {
-
     public function test_page_text_export()
     {
         $page = Page::query()->first();
@@ -133,7 +135,7 @@ class ExportTest extends TestCase
     {
         $page = Page::query()->first();
 
-        $customHeadContent = "<style>p{color: red;}</style>";
+        $customHeadContent = '<style>p{color: red;}</style>';
         $this->setSettings(['app-custom-head' => $customHeadContent]);
 
         $resp = $this->asEditor()->get($page->getUrl('/export/html'));
@@ -144,7 +146,7 @@ class ExportTest extends TestCase
     {
         $page = Page::query()->first();
 
-        $customHeadContent = "<!-- A comment -->";
+        $customHeadContent = '<!-- A comment -->';
         $this->setSettings(['app-custom-head' => $customHeadContent]);
 
         $resp = $this->asEditor()->get($page->getUrl('/export/html'));
@@ -209,8 +211,8 @@ class ExportTest extends TestCase
     {
         $page = Page::query()->first();
         $page->html = '<img src="http://localhost/uploads/images/gallery/svg_test.svg"/>'
-            .'<img src="http://localhost/uploads/svg_test.svg"/>'
-            .'<img src="/uploads/svg_test.svg"/>';
+            . '<img src="http://localhost/uploads/svg_test.svg"/>'
+            . '<img src="/uploads/svg_test.svg"/>';
         $storageDisk = Storage::disk('local');
         $storageDisk->makeDirectory('uploads/images/gallery');
         $storageDisk->put('uploads/images/gallery/svg_test.svg', '<svg>good</svg>');
@@ -273,7 +275,7 @@ class ExportTest extends TestCase
     {
         $page = Page::query()->first()->forceFill([
             'markdown' => '# A header',
-            'html' => '<h1>Dogcat</h1>',
+            'html'     => '<h1>Dogcat</h1>',
         ]);
         $page->save();
 
@@ -286,7 +288,7 @@ class ExportTest extends TestCase
     {
         $page = Page::query()->first()->forceFill([
             'markdown' => '',
-            'html' => "<h1>Dogcat</h1><p>Some <strong>bold</strong> text</p>",
+            'html'     => '<h1>Dogcat</h1><p>Some <strong>bold</strong> text</p>',
         ]);
         $page->save();
 
@@ -298,7 +300,7 @@ class ExportTest extends TestCase
     {
         $page = Page::query()->first()->forceFill([
             'markdown' => '',
-            'html' => "<h1>Dogcat</h1><p class=\"callout info\">Some callout text</p><p>Another line</p>",
+            'html'     => '<h1>Dogcat</h1><p class="callout info">Some callout text</p><p>Another line</p>',
         ]);
         $page->save();
 
@@ -310,7 +312,7 @@ class ExportTest extends TestCase
     {
         $page = Page::query()->first()->forceFill([
             'markdown' => '',
-            'html' => '<h1>Dogcat</h1>'."\r\n".'<pre id="bkmrk-var-a-%3D-%27cat%27%3B"><code class="language-JavaScript">var a = \'cat\';</code></pre><p>Another line</p>',
+            'html'     => '<h1>Dogcat</h1>' . "\r\n" . '<pre id="bkmrk-var-a-%3D-%27cat%27%3B"><code class="language-JavaScript">var a = \'cat\';</code></pre><p>Another line</p>',
         ]);
         $page->save();
 
@@ -340,4 +342,28 @@ class ExportTest extends TestCase
         $resp->assertSee('# ' . $page->name);
     }
 
+    public function test_export_option_only_visible_and_accessible_with_permission()
+    {
+        $book = Book::query()->whereHas('pages')->whereHas('chapters')->first();
+        $chapter = $book->chapters()->first();
+        $page = $chapter->pages()->first();
+        $entities = [$book, $chapter, $page];
+        $user = $this->getViewer();
+        $this->actingAs($user);
+
+        foreach ($entities as $entity) {
+            $resp = $this->get($entity->getUrl());
+            $resp->assertSee('/export/pdf');
+        }
+
+        /** @var Role $role */
+        $this->removePermissionFromUser($user, 'content-export');
+
+        foreach ($entities as $entity) {
+            $resp = $this->get($entity->getUrl());
+            $resp->assertDontSee('/export/pdf');
+            $resp = $this->get($entity->getUrl('/export/pdf'));
+            $this->assertPermissionError($resp);
+        }
+    }
 }